Using JavaScript, I am trying to replace an attribute inside an html tag, and have come up with this regex:
/<\s*tag[^>]*(attr)=['"]{1,1}([^'"\s]*)['"]{1,1}/ig;
This works. However, I want to be able to specify to look for the same type of quotation mark enclosing the attribute value. So, for example, I want to specify if this is the form <tag attr='data'>, to look in the SECOND quotation mark for the single one, not the double one. The inverse case, <tag attr="data"> would be similar; match the SECOND mark with double quotes, not single ones. This is to help me protect the function call against strangely formed HTML.
So, how can I achieve this?
Thanks!
Try this:
Explanation: