Greetings Monks,

This is probably a lot simpler than I am thinking it is, but I figured I'd ask. My brain's not been at full speed for days now, and so I'm having a hard time logic-ing through this

What I'm trying to do:
I have a series of text blocks, stored as array elements in an HoA. I am scanning the text elements for regex pattern matches, and formatting the matching patterns with <span> tags. Because the patterns are user-defined, I don't know if any of them are going to overlap, and so I want to toss in a brief check to see if the matches overlap, and if so, do something about it.

How I thought I'd do it:
My first thought is to scan the text, and for each <span> increment an index value, and for each </span>, decrement it. If at any point the index reaches a number above 1, perform an action. Does that make sense to people?

Second, the actions I'm doing with the span tags is basically just text-highlighting. My thoughts then are, if there are no open span tags (i.e., index = 0), highlight with specified color. If there are open span tags, than close the previous span tag prematurely, open a new one, and make the text color of the overlap text the color of the highlighting from the last span tag, and the highlighting of this text that specified for the current span. At the location of the previous span's original endpoint, change the text back to black, and keep the highlighting.

Of course, I need to be prepared for the possibility of a third overlapping pattern, but I am not sure how to work that. I am also not sure of what to do if 2 different matches start at the same location in the text. Well, I know what I want to do - make the text color match 1 pattern and the highlight color match the other, but I am not sure how to do it.

As I said, this probably isn't very hard to do, but my brain hurts.

If someone could please just toss together a quick outline of code, I would gladly and very thankfully finesse it to make it work the way I want, I'm just not thinking clearly enough to figure out how to start.

Thanks,
Matt


In reply to Keeping track of html tags by mdunnbass

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.