-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
  • 5,048
  • 4
  • 23
  • 42
Shoshin Nikita
  • 682
  • 1
  • 7
  • 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
  • 5,048
  • 4
  • 23
  • 42