Forum Moderators: coopster

Message Too Old, No Replies

Regular expressions & newline characters PHP

         

ktsirig

9:34 am on Feb 12, 2006 (gmt 0)

10+ Year Member



Hi all!
I have a preformatted text where I want to run a regular expression. The text is something like :

codeA

*->refbrjkgbrkjgbrjukbgreukgbrukgbegurebgrek


klgfhnrjkgnrjgbrejkgbrjkbegjkrbbrkegbrejb


reopjgporejytopjrotjrphjpojprhjtporhtjrph

codeB

*->4p3tuop43tu4optj4rofdgfnreklfnrklefnrkenr

ropeturojgorejgeolgjrelgjrlgrhelkghelghlg

regjrejgoejeojigjreilgjelgjrilgjlerjgelrj

From each 'paragraph', I want to match the part under codeA and codeB

The problem I have is with matching the newline characters. I write :

preg_match('/code.{1}\n\*->(.*)\ncode./')
but it doesn't match... I think the problem is the newlines

simon2263

12:13 pm on Feb 12, 2006 (gmt 0)

10+ Year Member



By default, the '.' special regex operator doesn't match the newline character. If this is the cause of your problem, you can modify this behaviour using the 's' regex modifier - see here: [uk2.php.net...]

FiSH42

3:50 pm on Feb 12, 2006 (gmt 0)

10+ Year Member



I don't know if this 'll help, but i tend to use nl2br() prior to doing ops on strings as '<br>' 's are always easy to pick out, and it will replace most forms of newline, as far as I'm aware.

freeflyer

8:58 am on Feb 13, 2006 (gmt 0)



Hello,
you can also consider \s* , because it include \n, and \n\r also.