my $foo = "bar road"; if ($foo =~ /\b\w+\s*(road)?/) { print "Matched:", $1, "\n"; }
In the above code in $1 road is captured which is as expected.
Now if I change the regex to /\b\w+\s*?(road)?/, that is, make the space matching lazy then "road" is not captured.
Can someone please tell me as to why this happens as soon as I make the space matching lazy?
In reply to Regex lazy behaviour by abhy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |