[support] preg_match failes where egrep and PERL succeed?
CM Lubinski
cmc333333 at gmail.com
Thu Feb 25 17:40:21 UTC 2010
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Just discovered that this could also be solved with the 'm' flag:
http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php
The 's' flag is also very useful if your expression will be matched
across lines.
Good to know!
CM Lubinski
Luke wrote:
> (Solved! See below for details.)
>
> On Wed, 3 Feb 2010, CM Lubinski wrote:
>
>> I think this is an issue with your escaping but my eyes are not keen
>> enough to see where the error is.
>
> Moving the code into an include, and running:
>
> drush 2> /dev/null eval 'include("/tmp/drupal.inc");'
>
> Gets me a no-matcher.
>
>> The regular expression itself works fine:
>> <?php
>> function get_matches($to_match) {
>> preg_match('/^\d{3}\|([0-9a-fA-F]+)/', $to_match, $match);
>
> That assumes a single search string. I hardcoded the "200" where you
> have "\d+", because what actually happens is that the three digit code is
> obtained on the fly from a variable. So the regex is to search a group of
> lines with that format, and when it gets to the one containing "200" at
> the start, kick back the second part.
>
> I tried it with your version, though, and it returned the first line's
> RHS, as I would expect--1 match.
>
> I've just figured it out. The difference between the greps and
> PCRE, is that in the greps, the data is taken on a line by line basis.
> So, ^ matches the start of a line.
> PCRE is not treating newline specially, so ^ and $ apply to the beginning
> and end of the entire pattern space.
>
> Rewriting it with:
>
> $res = preg_match('/\b' . $search_for . '\|([0-9a-fA-F]{6})/',
> $match_against, $match);
>
> gets the job done.
>
> Thanks for considering it.
>
> Luke
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkuGtgUACgkQfzi1OiZiJLAA8gCePDFVJ4986MPYwOQeKZMZM/J7
3PMAnAujSZKE1+BiWZ1ORri3Ae8Hkvb3
=f/AF
-----END PGP SIGNATURE-----
More information about the support
mailing list