abcde123483
abcde123483

Reputation: 3905

PHP regexp: matching everything until a word appears

In PHP I'm looking to match everything until a certain word appears:

$text = "String1

                         .

                  testtesthephepString2 Here";

$faultyregexp = "#String1(.+)String2 Here#";

preg_match($text, $faultyregexp, $result);

Now I want to match everything between String1 and String2, but for some reason this doesn't work.

I'm thinking you could do something like #String1(^String2 here+)String2 here# if you know what I mean :) ?

Upvotes: 1

Views: 530

Answers (1)

NikiC
NikiC

Reputation: 101936

The issue is that by default . does not include newline characters. If you want . to match all character, you need to specify the s modifier (PCRE_DOTALL):

/String1(.+)String2 Here/s

Upvotes: 5

Related Questions