views:

760

answers:

3

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

+1  A: 

Here is a tutorial on Dreamweaver's Regex. http://www.adobe.com/devnet/dreamweaver/articles/regular_expressions.html

Daniel A. White
Can you suggest me the expression like:[Start Text] [Anything] [End Text]So that I can search like:<iframe src [Anything] </iframe>
Prashant
+1  A: 

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

Paul Roub
+2  A: 

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.

Copas
Forward-slashes and equals signs have no special meaning in a regex; you don't need to escape them.
Alan Moore
In perl forward-slashes are often the separation characters for the regex string so I'm used to escaping them. Not sure why I had an escape on one of the equals and not the others. Fixed, thanks.
Copas