0

I need help to understand why this happens :

I have a string in the form of "'{{item}}'" (notice the single quotes inside double quotes).
So I wrote two regular expressions in order to remove single quotes and braces :

  • This one does not capture the last character : /{{|}}|'{{|}}'/g (result is "item'")
  • This one does : /'{{|}}'|{{|}}/g (result is "item")

I tried to replace the single quote by a random character, but no matter, the last character is never captured in the first regex, while it is in the second. Why ?

Célia
  • 279
  • 3
  • 11
  • Matches are prioritized in left-to-right order. – Pointy Apr 21 '20 at 23:22
  • 1
    Just use `s.replace(/'{{|}}'/g, '')`. `{{|}}` is not necessary if you always have single quotes. If they are optional use `s.replace(/'?{{|}}'?/g, '')`. – Wiktor Stribiżew Apr 21 '20 at 23:23
  • Yes they are optional. The regex with "?" is perfect, thanks ! :D As far as I understand, there is something wrong with closing double braces "}}" in regex, but I can't find why – Célia Apr 21 '20 at 23:34

0 Answers0