This approach is a variation on AnonyMonk's above:

c:\@Work\Perl>perl -wMstrict -le "use 5.010; ;; my $s = qq{Please;, read these&\x23xB0;, before you post 180;, if not + absolutely &\x23x2013;, sure.}; print qq{'$s'}; ;; my $entity = qr{ & [\x23] x [[:xdigit:]]+ ; }xms; ;; $s =~ s{ (?: $entity , (*SKIP) (*FAIL))? ; \K , }{}xmsg; print qq{'$s'}; " 'Please;, read these°, before you post 180;, if not absolutely &# +x2013;, sure.' 'Please; read these°, before you post 180; if not absolutely &#x2 +013;, sure.'

Some notes (update: now with more numbers for your indexing enjoyment):

  1. My REPL does not like the # character at all, so it has to be represented as  \x23 in strings and regexes, but it prints and otherwise operates as expected;
  2. The substitution regex uses features added with Perl version 5.10:  (*SKIP) (*FAIL) (see Special Backtracking Control Verbs), and  \K (see Extended Patterns);
  3. The  $entity regex is very naive (as is the one used by AnonyMonk) and you will have to come up with one that covers all your cases;
  4. The  (?: $entity , (*SKIP) (*FAIL))? sub-pattern acts as a variable width negative look-behind by 'consuming' (i.e., skipping past) something that is needed for a subsequent match, in this case a comma following an entity.


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


In reply to Re: Look Behind issues by AnomalousMonk
in thread Look Behind issues by dominic01

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.