Is there a nice way I can figure out whether my regexp has capturing matches in it? My question turned up with some code that (boiled down) needs to differentiate between these two cases:
my @x = ( "1234" =~ m/(\d)/ ); # @x contains a captured match of "1" my @y = ( "1234" =~ m/34/ ); # @y contains a "1" for a successful m +atch print "x=(@x), y=(@y)\n"; # x=(1), y=(1)
Now I guess I could set $1 to undef before the match and test it afterwards - but this seems so darn inelegant. Am I missing a trick?
In reply to Determing whether a regexp has capturing matches by adrianh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |