开发者

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 = "开发者_JAVA百科#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 :) ?


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜