-1

I need to replace following lines in XML file:

hashName="'Miecz Nieb. Wojownika+5IMiecz Nieb. Wojownika+5" name="Miecz Nieb. Wojownika+5"

As the above line is not correct, I want it to be replaced like this:

hashName="'Miecz Nieb. Wojownika+5'" name="Miecz Nieb. Wojownika+5"

(It should take the item name from the name="" attr!).

This is what I got at the moment, its not working as expected since it does remove my name="..." attribute.

Search for:

hashName="(')(.*)"(.)name="(.*)"(.)/

Replace with:

hashName="'\4'" name="\4"

Cœur
  • 37,241
  • 25
  • 195
  • 267
Cyclone
  • 14,839
  • 23
  • 82
  • 114
  • [On parsing XML or HTML with regular expressions](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – Benoit Dec 19 '11 at 07:37
  • 2
    You have a dot in your regex after the last quote, but since the final quote in the input is at the end, with nothing behind it, that won't match. – Mr Lister Dec 19 '11 at 07:44

2 Answers2

1

This should work

Search for: hashName=\".+\" name=\"(.+)\"
Replace with: hashName="'\1'" name="\1"
denis.solonenko
  • 11,645
  • 2
  • 28
  • 23
1

For this simple example this is working

Search for

hashName="[^"]*"\s*name="([^"]*)"

and replace with

hashName="'\1'" name="\1"

If you don't want to capture or group characters, don't put brackets around it, therefor I removed most of them.

To avoid that too much is matched, e.g. if you have two "name" attributes in one row, I used [^"]* to do a non greedy matching.

stema
  • 90,351
  • 20
  • 107
  • 135