Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 423
Odaat Avatar asked Feb 05 '19 14:02

Odaat


People also ask

How do you change all occurrences in VS Code?

Expand the Search widget to display the Replace text box. When you type text into the Replace text box, you will see a diff display of the pending changes. You can replace across all files from the Replace text box, replace all in one file or replace a single change.

How do I replace all occurrences in Visual Studio?

You can access replacement options by choosing the button next to the Find text box. To make one replacement at a time, choose the Replace Next button next to the Replace text box. To replace all matches, choose the Replace All button.


1 Answers

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.

like image 93
Mark Avatar answered Sep 21 '22 01:09

Mark