in reply to Regular Expression matching question
The output is as follows:$text = 'ab'; if ($text =~ /(a*)((?:ab)*|b*)/) { print "'$1', '$2' \n"; } if ($text =~ /(a*)(b*|(?:ab)*)/) { print "'$1', '$2' \n"; }
Incidentally, Perl uses a traditional NFA engine for regex matching. If it used the POSIX-NFA engine or a DFA engine, your regex would work as you expect because those engines try to find the longest match that satisfies the regex. If you have experience with those engines, Perl may cause you some confusion.'a', '' 'a', 'b'
Cheers,
Ovid
P.S. I'm glad to see you have a sense of humor about the flack you took :)
Update: Oops. dchetlin is right. I was typing too fast and didn't consider the DFA issue.
Join the Perlmonks Setiathome Group or just go the the link and check out our stats.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(dchetlin: DFA) RE: (Ovid) Re: Regular Expression matching question
by dchetlin (Friar) on Oct 25, 2000 at 01:20 UTC |