in reply to Re^2: Trouble capturing multiple groupings in regex
in thread Trouble capturing multiple groupings in regex

After thinking a bit more about this, the following approach using look-around assertion works:

use warnings; use strict; while (<DATA>){ my @matches; @matches = (/(?<=[%>])%([^%]+)%(?=[%<])/g); print join ' ', @matches; print "\n"; } __DATA__ <span color="#231f20" someattr="%do_not_match%" textOverprint="false"> +%PN1%</span> <span color="#231f20" someattr="%do_not_match%" textOverprint="false"> +%DIMMM%%DIMINCH%</span> __END__ PN1 DIMMM DIMINCH

Replies are listed 'Best First'.
Re^4: Trouble capturing multiple groupings in regex
by reverendphil (Initiate) on Dec 09, 2015 at 15:24 UTC

    That's it! Fantastic! Thanks so much. I'm going to finish up this report, and then figure out what exactly you did so I can understand this, but that worked absolutely perfectly. Here's hoping I don't come up with another strange scenario when I run this on 250 templates instead of 5. :)

      Here's hoping I don't come up with another strange scenario ...

      As has been noted many times in these precincts, attempting to parse XML with regexes is likely to lead you to the Hell of Exceptions. Maybe better to parse out the XML text bodies with an honest XML parser, then operate with regexes on the  %whatever% thingies therein?


      Give a man a fish:  <%-{-{-{-<