(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