Just for the sake of completeness, these are the two variants of alternations in Perl 6, adapting your example:
With a single pipe, the longest match wins (which means, BTW, that the engine must try all possibilities to figure out which is the best); with a double pipe, the first match wins.> my $s = 'xxxABCDEyyy'; xxxABCDEyyy > say "captured $/" if $s ~~ / ABC | ABCD | ABCDE /; captured ABCDE > say "captured $/" if $s ~~ / ABC || ABCD || ABCDE /; captured ABC
But that holds only if all possible matches start on the same atom:
Here, even though "ADCDE" is a longer match, "xABC" wins because it starts earlier in the string.> say "captured $/" if $s ~~ / xABC | ABCD | ABCDE /; captured xABC
In reply to Re^3: Is RegEx in Perl not NFA anymore?
by Laurent_R
in thread Is RegEx in Perl not NFA anymore?
by redbull2012
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |