[pcre-dev] need help with a particular regex

トップ ページ
このメッセージを削除
著者: Nuno Lopes
日付:  
To: pcre-dev
題目: [pcre-dev] need help with a particular regex
Hi,

Well, maybe this isn't the best place to ask these kind of questions, but I
didn't know of a better place :)

We use pcre in the PHP test-suite to match the expected output of a unit
test with its real output. However we found some problems with the regexes
we are using. For example, the following script gives a match, where we
didn't want to match:

<?php

$txt ="Warning: something wrong in function red at line 10\n".
"Warning: something wrong in function green at line 13\n".
"Write whatever you like, it will be swallowed at line 16\n";

$regex = "/^Warning: something wrong in function .+? at line \\d+\n".
         "Warning: something wrong in function .+? at line \\d+$/s";



preg_match($regex, $txt, $m);

?>

(The /s means PCRE_DOTALL).

This matches despite the usage of the ungreedy modifier. My idea was to use
some kind of ungreedy+possessive modifier (so that it would match the
minimal string locally and wouldn't backtrack to get a global match if
needed), but that doesn't seem to exist.
My question is if there is some way to express this with PCRE? (does the new
(*COMMIT) and the like features help here?)


Thanks in advance,
Nuno