adrianh has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Determing whether a regexp has capturing matches
by rhesa (Vicar) on Feb 27, 2007 at 15:52 UTC | |
by adrianh (Chancellor) on Feb 27, 2007 at 16:03 UTC | |
by kyle (Abbot) on Feb 27, 2007 at 16:08 UTC | |
by adrianh (Chancellor) on Feb 27, 2007 at 16:45 UTC | |
|
Re: Determing whether a regexp has capturing matches
by kyle (Abbot) on Feb 27, 2007 at 15:45 UTC | |
by adrianh (Chancellor) on Feb 27, 2007 at 15:58 UTC | |
by Limbic~Region (Chancellor) on Feb 27, 2007 at 17:15 UTC |