Page 1 of 1

replace based on variable within string

Posted: Thu Nov 10, 2011 12:01 pm
by AlanQ
With the text file I have a line like this

<IMG src="/pages/cat/jpgs/IRFMR_A.jpg">

And I need to change it to this

<a href="/pages/cat/jpgs/IRFMR_A .jpg" rel="prettyPhoto"><img src="/pages/cat/jpgs/IRFMR_A.jpg" align="middle" border="0" width="250"></a>

BUT the image filename, in this case IRFMR_A .jpg is different in each text file. So I need to extract the image filename and use it within the replace.

Is there any way to code this with regex??

I have thousands of these to do so any help much appreciated!

Thanks in advance

Alan

Re: replace based on variable within string

Posted: Thu Nov 10, 2011 2:45 pm
by AlanQ
solved my own problem, just posting for ther benefit of others. The solution is to create a group and use the group number:
so search for
<IMG src="/pages/cat/jpgs/(.*).jpg">
replace with
<a href="/pages/cat/jpgs/$1.jpg" rel="prettyPhoto"><img src="/pages/cat/jpgs/$1.jpg" align="middle" border="0" width="250"></a>

Great little program!