Search code examples
regexasp-classic

Regex to remove HTML attribute from any HTML tag (style="")?


I'm looking for a regex pattern that will look for an attribute within an HTML tag. Specifically, I'd like to find all instances of ...

style=""

... and remove it from the HTML tag that it is contained within. Obviously this would include anything contained with the double quotes as well.

I'm using Classic ASP to do this. I already have a function setup for a different regex pattern that looks for all HTML tags in a string and removes them. It works great. But now I just need another pattern for specifically removing all of the style attributes.

Any help would be greatly appreciated.


Solution

  • I think this might do it:

    /style="[a-zA-Z0-9:;\.\s\(\)\-\,]*"/gi

    You could also put these in capturing groups, if you wanted to replace some parts only

    /(style=")([a-zA-Z0-9:;\.\s\(\)\-\,]*)(")/gi

    Working Example: http://regexr.com?2up30