I can't make this regex work in javascript:
pat = new RegExp("Lorem(?=([^<]*($|<a|<[^/]|</[^a]))*($|(?<=a)))", "g");
test = test.replace(pat, '<a href="#">Lorem</a>');
I get the error: invalid quantifier
.
But here is working: http://gskinner.com/RegExr/?2va0g
Thanks for your help :)
EDIT
I need to replace every occurrence of "String" with a link, but only if "String" wasn't already a link.
Es.
This is a <a href="#">String</a>. This is another String.
=>
This is a <a href="#">String</a>. This is another <a href="#">String</a>.
Better if can check also the url of the link es:
This is a <a href="http://www.test.com/String">link</a>
=>
This is a <a href="http://www.test.com/String">link</a>
Probably is enough to replace all String that are not inside <a ... </a>
(the first a TAG is not closed on purpose)