1 Replies - 1945 Views - Last Post: 12 February 2006 - 10:29 PM Rate Topic: -----

#1 ktsirig  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 94
  • Joined: 14-September 05

PHP & newlines Regular expressions

Posted 12 February 2006 - 03:45 AM

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

Is This A Good Question/Topic? 0
  • +

Replies To: PHP & newlines Regular expressions

#2 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 64
  • View blog
  • Posts: 3,505
  • Joined: 31-March 03

Re: PHP & newlines Regular expressions

Posted 12 February 2006 - 10:29 PM

On default, preg_* ignores newlines when searching a string. I mean it sees them, but it only uses the first line.

To get around this, you just add s to the end of the expression.
preg_match('/expression/s', $string);

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1