http://www.perlmonks.org?node_id=813028


in reply to Re^4: Regex fun
in thread Regex fun

It still didn't work as needed. That didn't remove the bases after the +N.

I guess you mean the s/// while s/// code in Re^3: Regex fun? Yes, I know it doesn't work, but was just posting it as an example of what would work if Perl changed to fit my whims. :-) I should probably make that clearer.

The actual fixed-but-inelegant code is in Re: Regex fun, in an update at the bottom. I tested it on your input, and it seemed to give the desired output. (It doesn't handle -N escapes, which you seem to want, because I didn't see anything about that in your original specification; but it would be easy enough to adapt it.)

pos($_) -= length($1)+1;

You may want to try pos = $-[0] instead. See pos (for implicit action on $_) and @-.