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 Answers 4

3

find the following regular expression:

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

And replace it with

.getAttribute("attr"+\1)

http://regexr.com?33b0j <-- See it in action!

Sign up to request clarification or add additional context in comments.

Comments

0

You should use some wildcard replace tools in some text editor. I personally use VS. MS-Office programs such as word has that possibility too.

Comments

0

Find what: \.attribute\[(\d+)\]\.value;
Replace with: .getAttribute\("attr" + \1\);

(I had to escape the brackets in the replace value for my version of Notepad++ to)

3 Comments

You don't have to escape the brackets because of Notepad++, it's because brackets delineate character sets in Regular Expressions.
I'm talking about the replace value not the find value
Okay. Got confused because you don't have any brackets in your replace value, and thought you mistyped.
0

Tested with notepad++

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

replaced with

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.