tags:

views:

388

answers:

2

I've tried "m" modifier,but not working:

$reg = '/...
        /m';

preg_match($reg,...,$match);

EDIT

Or maybe I need a modifier that can ignore white space like ENTER,TAB and so on. Because when I remove the white space in my regex it works.

EDIT AGAIN:

I need a modifier so that regular expression

"/aaaa b/",
"/aaaa
 b/"

are the same thing,say,it just ignores the white space in regex itself.

A: 

You have probably a problem with dots not matching new lines in your regular expression. You can use the s modifier it will make dots match everything even new line.

Hope this helps

it would give

/aaaaaaa.+b/ms

Also would be a better practice to use \n because depending of your editor (Unix or windows) the newline could be different characters, CR + LF or only LF ... so your code won't be portable.

or to really ignore whitespace in the reg ex

function formatRegEx($reg){
 return preg_replace('/(\s+)/m', '\s+', $reg);
}
RageZ
I need to use RETURN in regex because it's very long.Otherwise it'll be hard to see what on earth it's doing.Anyway,by somehow,there is such a requirement.But how to enable this mode?
Shore
+3  A: 

The modifier you need is x

print_r(preg_match('/aaa
  bbb/x', 'aaabbb'));
too much php
Finally one understands me!Cheers!Clever guy!
Shore