I have a string, for example: <div style='text-align:center;' otherattr="script">
I want to allow specific attributes, for example allowing only the style attribute.
It should return: <div style='text-align:center;'>
I want to allow the attributes style, href, src, and align.
Thanks a lot.
As someone said in the comments, the best way to do this is to parse the string as an element and use DOM methods on it. REGEX is generally a bad idea for DOM handling.
This will allow
idattributes but remove any others.