Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I remove HTML elements with different values in VS Code using Find & Replace, while keeping its contents?

I’d like to remove all <a></a> elements (including classes, etc) in VS Code but keep the different values inside of the element. Is this possible using regular expression or another way?

This:

<td><a class="x">1</a></td>
<td><a class="y">2</a></td>
<td><a class="z">3</a></td>

Becomes:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<td>1</td>
<td>2</td>
<td>3</td>

>Solution :

I can help! Try the following in your find and replace tool for the find portion:

<a[^>]*>(.[^<]*)</a>

Then use the capture group for the replace portion:

$1

What this does is looks for <a then any number of characters that are not the closing angle bracket (>). Next it matches all characters up until the next opening angle bracket (<), then looks for the closing </a>. Finally, all the characters in the middle are what is used to replace the matched text, thanks to the capturing group $1.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading