I am trying to replace HTML content with regular expression.
from
<A HREF="ZZZ">test test ZZZ<SPAN>ZZZ test test</SPAN></A>
to
<A HREF="ZZZ">test test AAA<SPAN>AAA test test</SPAN></A>
note that only words outside HTML tags are replaced from ZZZ to AAA.
Any idea? Thanks a lot in advance.
Assuming a well-formed html document with outer/enclosing tags like
<html>, I would think the easiest way would be to look for the>and<signs:If you’re dealing with HTML fragments that may not have enclosing tags, it gets a little more complicated, you’d have to allow for start of string and end of string
Example JS (sorry, missed the tag):
Explanation: for each match that
>:\>>nor<:[^\>\<]*>nor<:[^\>\<]*<:\<Replace with
$1$2Using the “g” (global) option to ensure that all possible matches are replaced.