I'm trying to validate a username
string with the following characteristics:
- Not start with a
.
or_
- Not end with a
.
- Don't allow two
.
in a row - Only lowercase
letter characters
andnumbers
my code is username.matches('^(?!\.)(?!_)(?!.*\.$)(?!.*?\.\.)[a-z0-9_.]+$')
Using a regex simulator online it's working
https://regex101.com/r/bDXMg3/2/
But using the same syntax in Google RE2 Syntax (used in Firestore Security Rules) is throwing a ton of errors
I tried to then double escape each .
using the code username.matches('^(?!\\.)(?!_)(?!.*\\.$)(?!.*?\\.\\.)[a-z0-9_.]+$')
It only shows one error (red ^ sign at the beginning), but then it gives me the error below
Invalid regular expression pattern. Pattern: ^(?!\.)(?!_)(?!.*\.$)(?!.*?\.\.)[a-z0-9_.]+$.