Is there a reason you can't do this yourself?
I'm lazy. And a little bit out of my depth.
You'll need to document this in a little more detail
Update: This problem has been fixed. Finally :-)

The problem is was really simple, it's just a bit difficult to describe precisely and even more difficult to fix properly.

For every expression that matches, the script will would prefix the match with ANSI codes to change the color, then suffix it with another ANSI code to "reset" to the default color. If this overlaps with a previous match on the same line, the ANSI "reset" code will would remove any other color codes that should still have been in effect.

Example 1:
echo "aabbccddee" | em bbccdd red cc blue
would produce
aa[RED]bb[BLUE]cc[RESET]dd[RESET]ee
which is incorrect because the BLUE/RESET resets "dd" which should have been RED.

Example 2:
echo "aabbccddee" | em cc blue bbccdd red
would produce
aabb[BLUE]cc[RESET]ddee
because "bbBLUEccRESETdd" does not match "bbccdd".

I fear the only real solution would be to replace the simple regex substitute with a state machine that uses a color stack to see what color we should reset to. Unfortunately, this means we go from a quick and simple tool to a complicated piece of code that could fail even harder.

Instead of a simple substitution, I now keep an array of the codes I would insert. For each matching rule, I now scan this array to find the proper "reset color code" instead of just inserting a plain ANSI reset. Only when all the matching has finished I apply the codes using substr().

-- Time flies when you don't know what you're doing

In reply to Re^2: "em" - Emphasize text using regular expressions by FloydATC
in thread "em" - Emphasize text using regular expressions by FloydATC

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.