Page 1 of 1

Wildcard F/R

Posted: Tue Mar 13, 2007 7:42 pm
by MrG
I've checked through the other posts, and I think I understand how to do a variable find and replace, but I'm missing the obvious it seems...

I have a few html files that have code like this in it...
<IMG src="thumbnails/th_My%20Photo.jpg"

I need to replace it with:
<IMG src="../vwimages/th_My%20Photo.jpg/$FILE/th_My%20Photo.jpg"

So should I be doing a simple find and replace or a batch?

I think this is how it should be done...
search:
<IMG src="thumbnails/th_(.*).jpg"

replace:
<IMG src="../vwimages/$1/$FILE/$1.jpg"


Does this make sense at all?

Posted: Tue Mar 13, 2007 7:58 pm
by Abacre
In this version of Advanced Find and Replace you can use regular
expressions on Batch Replace tab.

The right regular expressions pair is:

Search for:
<IMG src="thumbnails/(th_.*)\.jpg"

Replace with:
<IMG src="../vwimages/$1/$FILE/$1.jpg"

. - dot before jpg is reserved char in search for (but not in replace
with!). So you have to escape it with \

Then in your example you have to put ( before th_

I verified it worked as expected.

Posted: Wed Mar 14, 2007 3:20 pm
by MrG
I see... so I should be putting this in the expression builder dialog box.. and not manually... correct?

BTW: It did work...

Mucho thanks..

Posted: Wed Mar 14, 2007 4:31 pm
by Abacre
For testing you should put it into Regular Expressions Builder.
Otherwise (for real replace) you should put it into Batch Replace
grid.

Posted: Fri Mar 16, 2007 8:38 pm
by MrG
Still doing some work on this... and for some reason the batch replace grid does not seem to like the '$FILE' piece... is the $ a reserved character?

I notice that it seems to duplicate a large part of the text of the document. e.g. I have a 5x5 table... after the replace, I have a 5 x 10 table.

Posted: Fri Mar 16, 2007 8:54 pm
by Abacre
Exactly. $ is a reserved char.

So in Search For part you should put \ before $ like this:
\$

But in Replace With part you can use $ without \

For example you can use $FILE in Replace With part but you should use
\$FILE in Search For part.

Posted: Mon Mar 19, 2007 1:44 pm
by MrG
Now what happens in the scenario where there is no "$FILE" in the search part, but is being added in the replace?

e.g. if I am searching for:
vwimages/(.*)\.jpg

and replacing with:
vwimages/th_$1.jpg/$FILE/$1.jpg"

The original string does not contain "$FILE" but is being inserted...

Even after some further testing, I guessing that "$FILE" is another reserved word... I think this copies the whole file and pastes it back in.. which might explain why my tables are being super-sized!