replace based on variable within string

Tool for Search and Replace across multiple files.
User avatar
AlanQ

replace based on variable within string

Post 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
User avatar
AlanQ

Re: replace based on variable within string

Post 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!
Post Reply