开发者

Regex to replace document.all

开发者 https://www.devze.com 2022-12-14 16:42 出处:网络
A simple (I hope) regex question: I have several pages where I need to replace every document.all[\'string\'] with document.getElementById(\'string\').

A simple (I hope) regex question:

I have several pages where I need to replace every document.all['string'] with document.getElementById('string').

I can use Visual Studio or Notepad++ to replace regular expressions, I just need the r开发者_运维百科ight ones.

Thanks for any assistance, Guy


For notepad++:

search:

document\.all\[\'(.*)\'\]

replace with:

document.getElementById('\1')


Replace

document\.all\['(.*?)'\]

by

document.getElementById('$1')

The parentheses are used to identify a group. The $1 is used to print the value of the first group. The backslashes are used to escape special characters in regex. For the remnant it's pretty trivial.

Hope this helps.


Search for:

document\.all\['([^']+)'\]

Replace with:

document.getElementById('\1')
0

精彩评论

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

关注公众号