Sorry, but I can't explain why.Because the .* before "vodka" eats "vodka" as well, as you can easily see if you add () around .*:
Changing the first .* to .*? does not help, either, because then the second .* eats "vodka".my $re = qr/beer=(\d{2})(.*)(?:vodka=(\d{2}))?(.*)chips=(\d{3})/; my $str1 = "beer=10&otherstuff&vodka=20&otherstuff&chips=100"; my $str2 = "beer=10&otherstuff&juice=20&otherstuff&chips=100"; say for $str1 =~ /$re/g; say "=="; say for $str2 =~ /$re/g;
In reply to Re^4: Likely trivial regex question
by choroba
in thread Likely trivial regex question
by moodywoody
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |