Reputation: 13
I want to search-replace a line that contains different addresses but I just want to search-replace a specific portion. Like
Search: < img border="0" src="*http://2.bp.blogspot.com/-OKZyRpnFLgw/UtqngoauEwI/AAAAAAADOlM/aXCJiiTRkaM/*s1600/005.JPG"/ >
Replace: < img border="0" src="*http://2.bp.blogspot.com/-OKZyRpnFLgw/UtqngoauEwI/AAAAAAADOlM/aXCJiiTRkaM/*s420/005.JPG"/ >
I just want to change the bold text. The Italic text changes in every file address.
I cant just simply search replace s1600 with s420 because it changes many other entries, I just want to make this change if it appears in < img address.
Help!
Upvotes: 0
Views: 56
Reputation: 14047
Using a Find what of (< img[^>]*?)s1600
and a Replace with of \1s420
will work on the line you give; you should have Regular expression selected. It will replace a single occurrence of s1600
between an < img
and the next >
. If you expect two or more s1600
between the strings then run the replace multiple times.
The Find what may not be strict enough. If text such as pqrs1600
or s160000
should not be altered then you could try (< img[^>]*?)\bs1600\b
.
If the s1600
always occurs between a *
and a \
as in the example then the Find what may be better as (< img[^>]*?\*)s1600/
and then the Replace with should be \1s420/
.
The basic idea in each case is to match the text that identifies where the item is and to capture that text using the round braces. The [^>]*?
matches zero or more characters that are not a >
, the *?
parts indicates a non-greedy match, so it matches the smallest sequence possible before the next part of the regular expression.
Upvotes: 1