Regex to match text only inside html tags

Say I have the following anchor tag

<a href="https://www.test.com" class="test-class">test</a>

I want a regex that only matches the test between the open and closing tag and ignores the attributes.

How can this be achieved? Would also like it to work across multiple lines if possible

Answer

  • Regex: you can select first sub grup.
/<.*?>(.*)<.*?>/g

Leave a Reply

Your email address will not be published. Required fields are marked *