Search code examples
visual-studio-codekmlvscode-tasks

VSCode: Delete all occurences of xml tag pair including differing contents


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


Solution

  • 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.