0

In a boatload of HTML pages, I need to replace all strings like this:

language[0].attributes[24].value;

with this:

language[0].getAttribute("attr"+24);

where '24' can be any number.

I thought I could use Notepad++'s Find and Replace with regular expressions to do this, but have had no luck so far after much trial and error. I don't want to have to do this manually.

(This is because, when I upgraded to IE10, all the text on the webpages I support went out of whack. It seems that by definition XML attributes can be in any order, and that newer versions of IE reorder them. I now need to reference the attributes by name instead of index.)

Appreciate the help.

4

4 回答 4

3

找到以下正则表达式:

\.attributes\[(\d+)\]\.value

并将其替换为

.getAttribute("attr"+\1)

http://regexr.com?33b0j <-- 看看它的实际效果!

于 2013-01-07T21:33:51.853 回答
0

您应该在某些文本编辑器中使用一些通配符替换工具。我个人使用VS。Word等MS-Office程序也有这种可能。

于 2013-01-07T21:34:56.993 回答
0

查找内容:\.attribute\[(\d+)\]\.value;
替换为:.getAttribute\("attr" + \1\);

(我必须将我的 Notepad++ 版本的替换值中的括号转义为)

于 2013-01-07T21:35:32.760 回答
0

用记事本++测试

language\[0\].attributes\[\s*(\d+)\s*\].value;

替换为

language[0].getAttribute\("attr"+\1\);
于 2013-01-07T21:38:11.833 回答