in reply to Re^5: why my reg ex matches greedy?
in thread why my reg ex matches greedy?
It's different if there is some following match condition:
use strict; use warnings; for my $reg ('(x\d{3,}?)', '(x\d{3,}?x)', '(x\d{3,})', '(x\d{3})') { for my $str ('xx', 'x12x', 'x123456x', 'x12x x123x') { print "Matched using $reg: $1\n" if $str =~ $reg; } }
Prints:
Matched using (x\d{3,}?): x123 Matched using (x\d{3,}?): x123 Matched using (x\d{3,}?x): x123456x Matched using (x\d{3,}?x): x123x Matched using (x\d{3,}): x123456 Matched using (x\d{3,}): x123 Matched using (x\d{3}): x123 Matched using (x\d{3}): x123
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: why my reg ex matches greedy?
by roboticus (Chancellor) on Jun 26, 2012 at 22:27 UTC |