Home > Mobile >  How do I remove HTML elements with different values in VS Code using Find & Replace, while keeping i
How do I remove HTML elements with different values in VS Code using Find & Replace, while keeping i

Time:07-13

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 >1</a></td>
<td><a >2</a></td>
<td><a >3</a></td>

Becomes:

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

CodePudding user response:

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.

  • Related