i’m nervous as hell asking this question since there’s a LOT of RegEx posts out there. but i’m asking for best method as well, so i’m going to risk it (fully expecting a rep hit if i botch the job…)
i’ve been given a list to reformat. 120 questions and answers (240 tag sets total). * glark * all i need to do is make the text between the tags a link, like so:
<li>do snails make your feet itch?</li>
has to become
<li><a href="#n">do snails make your feet itch?</a></li>`
THIS IS NOT A JAVASCRIPT/PHP RegEx question. it is JUST RegEx that i can drop into the search/replace fields of my IDE. i’ll likely try and do a batch replace afterwards with PERL to insert the 'n' variable so the links point properly.
and i know you’re going to ask ‘if you can use PERL for that, why not the whole shebang?’ and that’s a valid question, but i want to be using RegEx more for the power it has for big lists like this. plus my PERL skills are sketchy at best… unless you want to tack that on as well… 😀 heh heh.
if this question can’t be answered or is wrong for this part of the forum, please accept my apologies and point me in the right direction.
many thanks!
WR!
You can do it in two steps.
<li>with<li><a href="#n"></li>with</a></li>Or you can try to be clever and it it in one. Here is a substitute command in Perl syntax ($1 references what was matched in the brackets).
And while you are there it’s easy to replace the second part of the replacement pattern with an expression that will increment
nSee how you can run this from the command line: