Hi All, I have files that have some special markers in them something like this:
<5b>I <5c>like <5d>tacos
I was wondering if there was anyway possible to make the regex engine ignore these tags without deleting them? For example, if I had a regex like this:
s/(\w+)\s+tacos/$1 yummy tacos/g;
I would want it to change the above phrase to:
<5b>I <5c>like yummy <5d>tacos
I realize I could change the regex to:
s/(\w+)\s+(<\w\w>)?tacos/$1 yummy $2tacos/g;
but my script requires quite a few complicated regexes substitutions and having optional "(<\w\w>)?"s everywhere will make the regexes very ugly and make it hard to keep track of which capturing parenthesis are catching what.
I was wondering if there was a way to make the regex engine see the a string something like this where it would do its matching just against the first element in each sub array:
$string = [ ['I','<5b>'], [' '], ['l','<5c>'], ['i'], ['k'], ['e'], [' '], ['t','<5d>'], ['a'], ['c'], ['o'], ['s'] ]
Another possibilty I have considered and tried was erasing all the tags and then after I was done with all the substitutions doing a diff and trying to reconstruct where the tags should go. This actually works but was way too slow.

In reply to Skipping special tags in regexes by fletcher_the_dog

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.