1

I was wondering, what is the best way to implement the following case:

vm.elasticQuery = userQuery.replace(/~='[a-zA-Z]+'/g,':*[a-zA-Z]+*')

In other words, I would like to replace every pattern that looks like this ~='SomeLetters' to a pattern that looks like this :*SomeLetters*. Take into account that I do not want to remove/change the alphabets but only the outside.

Your help is appriciated.

user3819295
  • 861
  • 6
  • 19
  • The rule is the same across all NFA regex libraries: use a capturing group in the pattern and replacement backreferences in the replacement -> `.replace(/~='([a-zA-Z]+)'/g,':*$1*')` – Wiktor Stribiżew Oct 31 '19 at 09:08

0 Answers0