I need help writing a regular expression to parse a string of HTML to replace encoded quotations inside of the style
attribute. There is content in my HTML string that contains the same encoded quote that should NOT be replaced (not inside style tags). Here's my failed RegEx:
/style=".*(")*.*"/ig
Obviously, this is wrong because I have very little skill when it comes to RegEx. For example, here is what I am trying to replace:
<p style="font-family:"Times New Roman" color: red; background:url("whatever");">test1</p><p style="font-family:"Times New Roman" color: blue;">THIS IS CONTENT "DO NOT REPLACE!"</p><p style="font-family:"Times New Roman" color: green;">test</p><p style="font-family:"Times New Roman" color: orange;">test2</p>
My desired output:
<p style="font-family:'Times New Roman' color: red; background:url('whatever');">test1</p><p style="font-family:'Times New Roman'; color: blue;">THIS IS CONTENT "DO NOT REPLACE!"</p><p style="font-family:'Times New Roman' color: green;">test</p><p style="font-family:'Times New Roman' color: orange;">test2</p>
All instances of "
should be replaced that are inside of style="…"
, but not the ones in the content areas of HTML tags. Any help here is greatly appreciated!