MOO-cows Mailing List Archive


Yet another match error

I don't know if this error was already posted here as I do not read MOO Cows.
If it was, I apologise but nevertheless state that this error is quite serious,
especially to someone like myself who use regular expressions a lot.

;substitute("%1+%2+%3+%4",match("me as A guy in the mood for maths","^%(.+%) +%(in +%([^ ]+%) +%)?as +%(.*%)$"))
=> "me+as A guy in the +t+A guy in the mood for maths"

Now, I thought this was fishy, look at the same in Perl:

$_="me as A guy in the mood for maths";
print "$1+$2+$3+$4" if /^(.+) +(in +([^ ]+) +)?as +(.*)$/;

Result: me+++A guy in the mood for maths

A little strange how %(in +%([^ ]+%) +%)? matched 'as A guy in the ' and the
inner parenthesis matched 't'...

                                 |@ @|
 ,-------------------------vvvV--<o o>--Vvvv---------------------------------.
 |           Rui Mendes           V"V                                        |
 |            Any sufficiently advanced technology |
 |          is indistinguishable from magic.   |
 |      Finger me for PGP key                     Arthur C. Clarke           |


Home | Subject Index | Thread Index