-1

I'm new to regular expressions, therefore I need some help.

I have a string. For example:

"Some words <img src="www.test.com">. Next words <a href="www.abc.com">abc</a>"

I want to delete all tags except <a></a>. Can I create one regex or I should to make several regular expression?

Expected output:

"Some words. Next words <a href="www.abc.com">abc</a>"

GalAbra
  • 4,739
  • 4
  • 21
  • 39
Shoshin Nikita
  • 552
  • 1
  • 6
  • 11

1 Answers1

1

Even though you shouldn't use regex to parse HTML, this regex will capture all the non-<a> tags:

<\/?[^a\/].*?>
GalAbra
  • 4,739
  • 4
  • 21
  • 39