in reply to Re: how to make // not return what is in a parenthesis?
in thread how to make // not return what is in a parenthesis?

I agree that the code given in the OP doesn't make sense, especially with respect to the output shown.

However, the first regex given in the OP, 'A(BC|)(.*)D', is actually not far from working (insofar as I understand what beanryu really wants to do).

The  (BC|) group will match either 'BC' or the empty string. Just making this group non-capturing would be a big step forward. (My own preference for expressing this pattern would be (?:BC)? .) The next step would be to make the quantifier in the second (capturing) group lazy: (.*?) . (However, since beanryu seems to want to capture digits, I would rather express this as (\d+) .)

With just these changes, the regex actually works more or less as beanryu seems to want:

>perl -wMstrict -le "my $s = 'ABC1D A2D'; my @matches = $s =~ /A(?:BC|)(.*?)D/g; print qq{'$_'} for @matches; " '1' '2'