perlquestion
fletcher_the_dog
Hi All,
I have files that have some special markers in them something like this:<br>
<i><5b>I <5c>like <5d>tacos</i><br>
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:
<CODE>
s/(\w+)\s+tacos/$1 yummy tacos/g;
</CODE>
I would want it to change the above phrase to:<br>
<i><5b>I <5c>like yummy <5d>tacos</i><br>
I realize I could change the regex to:
<CODE>
s/(\w+)\s+(<\w\w>)?tacos/$1 yummy $2tacos/g;
</CODE>
but my script requires quite a few complicated regexes substitutions and having optional "<CODE>(<\w\w>)?</CODE>"s everywhere will make the regexes very ugly and make it hard to keep track of which capturing parenthesis are catching what.<br>
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:
<CODE>
$string = [
['I','<5b>'],
[' '],
['l','<5c>'],
['i'],
['k'],
['e'],
[' '],
['t','<5d>'],
['a'],
['c'],
['o'],
['s']
]
</CODE>
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.