I'm trying to validate user inputed tokens.
My rule is, if the user enters a string between dual braces, {{myToken}}
then only specific words will be allow to be placed between them. For this example, let's say "dog" and "cat" are valid, but invalid for anything other strings inside the braces. If no braces are present, then any strings are allowed.
I've found writing the a simple to detect dog or cat is quite easy.
test sentence 1:
- "I own a {{dog}} and {{cat}} but not a fish" -- valid
/{{(dog|cat+?)}}/g
But, I still want this sentence to be valid as well:
test sentence 2:
- "I own a fish" -- valid
And finally, this sentence should be invalid:
test sentence 3:
- "I own a {{cow}}" -- invalid