开发者

Reg Exp To Remove 'onclick' from HTML elements (Notepad++)

开发者 https://www.devze.com 2022-12-14 08:48 出处:网络
I have a big html file (87000+ lines) and want to delete all occurrences of onclick from all elements. Two examples of what I want to catch are:

I have a big html file (87000+ lines) and want to delete all occurrences of onclick from all elements. Two examples of what I want to catch are:

 1. onclick="fnSelectNode('name2',2, true);"
 2. onclick="fnExpandNode('img3','node3','/include/format_DB.as开发者_StackOverflow社区p?Index2=3');"

The problem is that both function names and parameters passed to them are not the same. So I need a Regular expression that matches onclick= + anything + );"

And I need one that works in Notepad++

Thanks for helping ;-)


Not familiar with notepad++, but what I use in vim is:

onclick="[^"]+"

Of course this depends on there being double quotes around the onclick in every case...


This regular expression will fail if you have a " or ' character included within quotes escaped by a \. Other than that, this should do it.

(onclick="[^"]+")|(onclick='[^"]+')


onclick="[^"]+" works for me, for that 2 strings.


If you want to go with a regex:

/onclick=".*?"/

You could also use something which is DOM-aware, such as a HTML/XML parser, or even just load up jQuery:

$("[onclick]").removeAttr("onclick");

... and then copy the body HTML into a new file.


Could

onclick=\".+;\"

Work?


 onclick=\".*\);\"


This regex should do the trick.

(\s+onclick=(?:"[^"]+")|(?:'[^']+'))


Open your file on dreamweaver, choose edit from the toolbar, select find and replace,

put onclick="[^"]+" in find field and keep replace blank

this will do the whole thing.

Enjoy

0

精彩评论

暂无评论...
验证码 换一张
取 消