Perl's regex engine finds the left-most match
I would have phrased it like this: like most engines Perl's looks by default for the longest leftmost match.
% stephan@labaule (/home/stephan) % % echo "okay stephan do test it!" | + > perl -lne 'm!(steph.?)!; print "seen: [$1]\n"' seen: [stepha]
Actually POSIX mandates longest possible for alternations as they all start at the same place. The owl book calls that POSIX NFA.
% stephan@labaule (/home/stephan) % % echo "okay stephan do test it!" | > perl -lne 'm!(steph|steph.?)!; print "seen: [$1]\n"' seen: [steph]
so yes, perl's is not POSIX NFA (for various efficiency reasons)
Actually not many engines follow POSIX on this, mostly (ugly -- because too ancient) system libraries (on Un*x), ksh's does too, even the Hackerlab library does (on second thought seems normal as it was supposed to be a drop-in replacement for the C lib on Un*x -- and POSIX). Tcl's is hybrid so I am not sure. And every engine after Perl5 birth has essentially copied Perl's.
regards --stephanby the way ksh notation is interesting (zsh can masquerade as ksh for this if you don't have a ksh to try)
In reply to Re^2: question about the star(*) quantifier
by sgt
in thread question about the star(*) quantifier
by snowsky
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |