8

I'm working in a kml (xml) file in VSCode. There are 267 instances of the <description></description> tags with the same contents schema but different contents. I would like a fast way to delete all of the instances of <description> including the contents instead of manually deleting each one. I'm not married to VSCode if Notepad++ or another editor will do what I'm trying to do.

Use one command/macro to delete both of these (plus 265 more)

<description><![CDATA[<center><table><tr><th colspan='2' align='center'> 
<em>Attributes</em></th></tr><tr bgcolor="#E3E3F3">
<th>NAME</th>
<td>Anderson</td>
</tr><tr bgcolor="#E3E3F3">
</tr></table></center>]]>
</description>

<description><![CDATA[<center><table><tr><th colspan='2' align='center'> 
<em>Attributes</em></th></tr><tr bgcolor="#E3E3F3">
<th>NAME</th>
<td>Billingsly</td>
</tr><tr bgcolor="#F00000">
</tr></table></center>]]>
</description>

Thank you, Paul

Odaat
  • 95
  • 1
  • 6

1 Answers1

17

You can use this regex in vscode find/replace:

\n?<description>[\S\s\n]*?<\/description>\n?

and replace with nothing. The \n?'s at the beginning and end are there if you want to delete the lines the tags occur on as well - see how it works, you can remove those if you don't care about empty lines where your deleted content used to be.

Obviously, if you have malformed input, like unmatched <description> or </description> tags the regex won't work.

Mark
  • 143,421
  • 24
  • 428
  • 436
  • This did exactly what I asked for. Thank you for saving me a considerable amount of time, which of course will now be lost looking more into regular expressions and how to use them in VSCode. I voted on it and saw a check come up. I hope I did this right as I've never posted a question before. – Odaat Feb 06 '19 at 01:15