I'm struggling to get a string replaced in Javascript by a regex matching pattern. I want to replace all matches of {{$myparam}} to be surrounded by a span tag. This works (see code below). But I want to prevent replacements when a match is preceded by href=".
Example: href="{{$myparam}}
must NOT be replaced.
{{$myparam}}
MUST be replaced.
myparam can be any text string.
var highlighted = html.replace(/(\{\{(.*?)\}\})/g, function highlight(x) {
return "<span class='highlight'>" + x + "</span>";
});
I've checked out numerous examples in other threads, but I cannot find a solution that works for my case.