I'm struggling with a regular expression. I'd like to strip out all data- attributes from html elements using regular expression. For example let's say I have this text:
<a href="" data-foo data-foo-bar data-test="foo" data-foo='blah'>
testing data-foo attributes.
</a>
I'd like to remove all data-* if it's inside of an HTML tag, but not from the text. The result should be:
<a href="">
testing data-foo attributes.
</a>
This is what I have, but it inappropriately strips out data-* from text:
/(data-.+?=".*?")|(data-.+?='.*?')|(data-[a-zA-Z0-9-]+)/g