Am trying to find a regex expression for this result:
string => should be matched (a single word or set of words at the beginning or the ending)
string => should be matched (a single word or set of words in the middle)
{{string}} -- should not be matched (a single word or set of words surrounded by two "{}" should not be matched)
am using this regex in this function :
text = text.replace(RegExp("([^{]{2})[^(\d:)]" + aTags[index].textContent + "\w*
([^}]{2})", 'i'), "{{" + index + ":" + aTags[index].textContent + "}}");
the function should find the textContent of an 'a' tag in a 'text' string and replace it by adding a digit and ':' to the beginning of the textContent so that the result should be something like this :
some text => will became => {{1:some text}}

text.replace(RegExp("{{.*?}}|(" + aTags[index].textContent + ")\\w*", "i"), function($0, $1) { return $1 ? "{{" + index + ":" + $1 + "}}" : $0;} ), see jsfiddle.net/4bpkzhtd/1.text = text.replace(RegExp("{{[^}]+}}|(" + aTags[index].textContent + ")", 'gmi'), function (match, $1) { if($1) return $1 ? {{${index}:${$1}}} : match; });worked on regex101 but in javascript i get this errorInvalid regular expression: /{{[^}]+}}|(*SKIP what's to avoid approach)/: Nothing to repeat{{...}}, but I do skip it in the code.text = text.replace(RegExp("{{[^}]+}}|(" + aTags[index].textContent + ")", 'gmi'), function (match, $1) { return $1 ?{{${index}:${$1}}}` : match; });` it worked now , thanks