How to enable free space mode in regular expression in PHP?

I tried the "m" modifier but did not work:

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

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

EDIT

Or maybe I need a modifier that can ignore spaces like ENTER, TAB, etc. Because when I remove the space in my regular expression, it works.

EDIT AGAIN :

I need a modifier to regex

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

- the same thing, say, it just ignores the space in the regular expression itself.

+5
source share
2 answers

Modifier you need x

print_r(preg_match('/aaa
        bbb/x', 'aaabbb'));
+8
source

, , , . s, .

,

/aaaaaaa.+b/ms

\n, (Unix windows) , CR + LF LF... .

reg ex

function formatRegEx($reg){
 return preg_replace('/(\s+)/m', '\s+', $reg);
}
0

All Articles