0

I have long lists of location data, which is in XML format.

<location><city>London</city><name>Zoo</name><latitude>...</location>

Unfortunately the XML is corrupt and I have to replace/fix a lot of invalid close XML tag occurances. Example, here </name> has to be replaced with </city>:

<location><city>London</name><latitude>...</location>

Using TextWrangler Find+Replace I can search for:<city>[A-Za-z]*</name> That statement searches and finds all the invalid lines. So far so good.

Now I want to replace them automatically (Replace All). Normally in regular expressions this is done by defining: <city>%1</city> but that is not working. It overwrites the found text, not interpreting the search result nor inserting the value in the %1 tag.

Vincent
  • 4,342
  • 1
  • 38
  • 37

1 Answers1

0

You need to capture the in-between characters using capturing group, so that you can reference the captured chars in the replacement part by specifying it's index number like %1 or \1 or $1

<city>([A-Za-z]*)</name>
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
  • Works perfectly with the the \1 options. The grouping did the trick! Thanks. (Note: the %1 and $1 don't seem to work) – Vincent Jan 14 '17 at 17:16