in reply to Determing what part of a regex matched.

The $+ is handy for this sort of thing. See perlvar. (You need capturing parenthesis on each alternative if you do it that way, though). Here's an example I did once:
push(@wds, $+) while $ln =~ m/(\d[.@]\d) | (\{[^}]+\}) | (\d) | (\w+\[[^\]]*\]) | (\w+) | ([\S])/xg;

Replies are listed 'Best First'.
Re: Determing what part of a regex matched.
by Abigail-II (Bishop) on Mar 06, 2003 at 01:06 UTC
    Why so complicated? If you want to capture what was matched, just put a single set of parens around the entire regex.

    But I didn't get the impression that that was the question. I think the question was, what part of the regex matched.

    Abigail