Perl regular expression return value with alternate matches
Created: 8 February 2006 Modified:Originally published on chrislynch.info website.
When writing a perl script I found that returning values from the regular expression did not work correctly with alternate matches. In other words when Perl$text =~ /^wcm\_([A-Za-z0-9]*)/|^wcm\_([A-Za-z0-9]*)\_([A-Za-z0-9]*)/gi
and the second condition was met it was returning the expected value for $1 as $2. Something I just thought of was that maybe with the second alternate it would return as $3 because the return value parenthesis was being counted for the whole expression rather than per alternative. I did not test this. Would be interesting to know