- The first Regular Expression Library on the Web!

Please support RegExLib Sponsors


Regular Expression Details

Title Test Find Strip HTML tags with exceptions
This regex will match all HTML tags except 'a' tags or 'img' tags. You can edit the list of exclusions as you see fit. I use this regex to strip all HTML tags from source data except anchor tags and image tags.
<script> </html> <anytag>
<a> <img /> </a>
Author Rating: The rating for this expression. Charles Forsyth
Your Rating
Bad Good

Enter New Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Use replace
Name: Charles
Date: 1/7/2016 1:58:40 PM
Use replace. This matches any tag that is not in the list, as described. So replace any match with an empty string to remove tags that are not <a> or <img>. But you can add any tagname you wish with or pipe delimiters. e.g. (a|i|b|strong)

Title: Seems to do the opposite
Name: Neil McLeish
Date: 1/4/2012 5:13:45 AM
Hi. I hav etried this and the tags which got stripped from my source were the anchor tags. This regex therefore, seems to do the exact opposite of its decription. Regards, Neil.

Copyright © 2001-2021, | ASP.NET Tutorials