-1

I need to verify this pattern:

{{ a valid variable name }}

Something like this:

/{{aaaa}}     ---> matches
/{{a}}        ---> matches
/{{a1a}}      ---> matches
/             ---> matches
/{aaa}}       ---> no matches
/{aaa}        ---> no matches
/{{aaa}       ---> no matches
/aaa}}        ---> no matches
/{{aaa        ---> no matches

and so forth...

I have this pattern:

^\\/(({){2}[A-Za-z0-9]+(}){2})*$

According to https://www.debuggex.com/#cheatsheet it is well written, but it doesn't work. Any suggestion on how to solve this?

isherwood
  • 58,414
  • 16
  • 114
  • 157
assembler
  • 3,098
  • 12
  • 43
  • 84
  • What does it mean by "it doesn't work"? Which tests does it fail? – Sweeper Apr 13 '20 at 14:45
  • `^\{{2}[\w]+\}{2}$` can you please try this – Tshiteej Apr 13 '20 at 14:47
  • It is not a good practice to downvote without saying why. Also, this question has nothing to do with the suggested https://stackoverflow.com/questions/4674237/javascript-regex-with-escaped-slashes-does-not-replace, completely different questions. – assembler Apr 14 '20 at 13:08

1 Answers1

1

At the start, you need to escape the / correctly:

^\/(({){2}[A-Za-z0-9]+(}){2})*$
 ^

Also, this can be simplified by removing the {2}:

^\/(({{)[A-Za-z0-9]+(}}))*$