Please help to rewrite all links without "target" attribute.
For example, the text is:
<a href="google.com" onclick="alert('Hello!!')">My Link 1</a>
<a href="my.com" class="some-class">My Link 2</a>
<a href="dot.net" target="_parent" class="some-class">My Link 3</a>
<a href="find.me" class="some-class">My Link 4</a>
The text is needed to got:
<a href="google.com" onclick="alert('Hello!!')" target="_blank">My Link 1</a>
<a href="my.com" class="some-class" target="_blank">My Link 2</a>
<a href="dot.net" target="_parent" class="some-class">My Link 3</a>
<a href="find.me" class="some-class" target="_blank">My Link 4</a>
3rd link is untouched, other links have attribute "target" now.
Please help to compose Regular Expression correct. I tried this:
Regex.Replace(text, "<(a)([^>]+)(((?! target=).)*$)([^>]+)>", "<$1 target=\"_parent\" $2 $3>");
but it's not working.
"Html Agility Pack" is undesirable.