mtoy
mtoy

Reputation: 195

preg_match_all does not support \n

I have small problem with preg_match_all and \n

MY reqular expression:

/\s*DEF\s+FUNC\s+(\w+\d*)\((\w*[,\s\w]*|)\)\s*{\s*(.*)\s*};/

it works for text:

DEF FUNC test() 
{
    test1
};

but this doesnt work for text:

DEF FUNC test() 
{
    test1
    test1
};

I'm fighting with this 3 hours ;/ Can somebody help me ?

Thanks

Upvotes: 1

Views: 185

Answers (2)

pwolaq
pwolaq

Reputation: 6381

According to this: http://php.net/manual/en/reference.pcre.pattern.modifiers.php

you have to use the s (PCRE_DOTALL) flag

Upvotes: 2

Robin
Robin

Reputation: 9644

The wildcard . doesn't match newlines by default.

If you want it to, you have to add the flag s (PCRE_DOTALL):

preg_match_all($regex, $in, $out, PCRE_DOTALL)

Upvotes: 1

Related Questions