I am trying to match a series of words that span across 2 lines.
Say I have the following text:
this is a test
another line
My Regular Expression pattern using preg_match:
/test.*another/si
Test here: http://www.phpliveregex.com/p/2zj
PHP Pattern Modifiers: http://php.net/manual/en/reference.pcre.pattern.modifiers.php
Everything that I've read points to using the "s" modifier to enable the "." character to match new lines, but I cannot get this to work. Any ideas?
Your regular expression is correct and works fine on my local machine:
$input_line = "this is a test
another line";
preg_match("/test.*another/si", $input_line, $output_array);
var_dump($output_array);
it produces the following output:
array(1) {
[0]=>
string(13) "test
another"
}
So my guess is that phpliveregex.com is not working properly and giving you false results.
Put the modifier in the regex:
/(?s)test.*another/i
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With