How to make regular expression for Dreamwaver find and Replace?
-
22-08-2019 - |
Question
I have the following code in about 300 HTML files, I need to replace it with some other code. But the problem in following code is the ID click=12FA863
is change and different in each file, I want to use the regular expression which will work in Find and replace in Dreamwaver.
<iframe src="http://example.net/?click=12FA863" width=1 height=1 style="visibility:hidden;position:absolute"></iframe>
Thanks
Solution
Put
<iframe src="http://example\.net/\?click=[^"]+" width=1 height=1 style="visibility:hidden;position:absolute"></iframe>
in your find field and whatever you want to replace it with in your replace field and you should be set.
OTHER TIPS
Here is a tutorial on Dreamweaver's Regex.
http://www.adobe.com/devnet/dreamweaver/articles/regular_expressions_pt1.html
If, as you said in your comment, you want to replace
<iframe src [Anything] </iframe>
Then this will do:
<iframe src.+</iframe>
Where "." means "any character" and "+" means "1 or more of them"
If you care about the click ID value, or some other part, you'd want to capture it, like so:
<iframe src.+click=([A-F0-9]+).+</iframe>
and use $1 (or $2, $3, etc. if you add more) when replacing.
Note that [A-F0-9]+ just means "one or more hex characters"
So if you used that regex, and this as the replacement:
<div>something else using $1</div>
Then
<iframe src="http://example.net/?click=12FA863" width=1 height=1 style="visibility:hidden;position:absolute"></iframe>
Would become
<div>something else using 12FA863</div>
I'd definitely spend some time at the tutorial Daniel recommended, and also look at other Regex tutorials, cheat sheets, etc. such as visibone.com/regular-expressions
<iframe.+?</iframe>
This is a lazy regexp, that looks for the finisher tag </iframe>
.
This regexp doesn't care where the src
is, it will find <iframe width... src=.. ></iframe>
too.