Wildcard F/R

General discussions about Advanced Find and Replace
Post Reply
MrG
Posts: 4
Joined: Tue Mar 13, 2007 7:13 pm

Wildcard F/R

Post 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?

Abacre
Site Admin
Posts: 1223
Joined: Mon Jan 31, 2005 5:32 pm

Post 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.
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

MrG
Posts: 4
Joined: Tue Mar 13, 2007 7:13 pm

Post 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..

Abacre
Site Admin
Posts: 1223
Joined: Mon Jan 31, 2005 5:32 pm

Post by Abacre »

For testing you should put it into Regular Expressions Builder.
Otherwise (for real replace) you should put it into Batch Replace
grid.
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

MrG
Posts: 4
Joined: Tue Mar 13, 2007 7:13 pm

Post 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.

Abacre
Site Admin
Posts: 1223
Joined: Mon Jan 31, 2005 5:32 pm

Post 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.
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

MrG
Posts: 4
Joined: Tue Mar 13, 2007 7:13 pm

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

Post Reply