in reply to Regex: return the pattern instead of the actual match

Wrap the parts of your regex definition into named capture groups, then inspect the %+ hash after matching. The info is in perlre.
  • Comment on Re: Regex: return the pattern instead of the actual match

Replies are listed 'Best First'.
Re^2: Regex: return the pattern instead of the actual match
by JavaFan (Canon) on Sep 15, 2011 at 11:43 UTC
    Rubbish. The keys of %+ gives you the names of the capture group, the values give you the part of the string that's matched. It doesn't give you the (sub)pattern.
      Re-Rubbish! It's a very good advice.

      Associating the name of the capture group to the subpattern solves the problem.

      Cheers Rolf

        Really? How does that work? How do you re-construct the subpattern from the (not necessarely unique) label you've given it? And why can't you do the same magical trick with the unique numbered match?
Re^2: Regex: return the pattern instead of the actual match
by Deus Ex (Scribe) on Sep 16, 2011 at 06:04 UTC

    Hi,

    sadly, I have no access to a more recent perl version than the 5.8.8, so I can't use no named grouping within regex's. Thanks though for the advice!