PHP preg_match (.*) not matching past line breaks

Norse picture Norse · Oct 1, 2012 · Viewed 44.9k times · Source

I have this data in a LONGTEXT column (so the line breaks are retained):

Paragraph one
Paragraph two
Paragraph three
Paragraph four

I'm trying to match paragraph 1 through 3. I'm using this code:

preg_match('/Para(.*)three/', $row['file'], $m);

This returns nothing. If I try to work just within the first line of the paragraph, by matching:

preg_match('/Para(.*)one/', $row['file'], $m);

Then the code works and I get the proper string returned. What am I doing wrong here?

Answer

Tasso Evangelista picture Tasso Evangelista · Oct 1, 2012

Use s modifier.

preg_match('/Para(.*)three/s', $row['file'], $m);

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