DoomGuyMM2 DoomGuyMM2 - 1 year ago 54
HTML Question

Remove content from two html tags

i have aprox. 200 files with different content in

<head> </head>
. I want to replace it and leave it with nothing.

Is there a regular expression for Notepad++ or something like that?

I had this regular expression:


But for some reason (that i don't know) it doesn't works in these files.

Answer Source

[^<>]+ means to match one or more characters other than < or >. That is, the full regular expression that you show is looking for <head> followed by some non < and > characters, followed by </head>.

But most HTML documents will have a <head> element that contains < and > characters in order to define other elements like <title> and so forth, so your regex will not match those.

Try this:


I.e., use .+ to match any characters in between the opening <head> and closing </head>. Then in Notepad++'s Find/Replace window make sure you've selected the "Regular expression" radio button and ticked the ". matches newline" checkbox. If you also want to match completely empty <head> elements then change .+ to .*.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download