Reputation: 21
I'm writing Security Rules for my Firebase Firestore project, but I can't seem to find a reference that exemplifies the correct syntax for using matches() method with a regular expression as the parameter. Here's what I use now:
request.resource.data.str.matches("^[a-z0-9]+$");
My question is now, where to put the case-insensitive flag "i" in the expression? I tried some different combinations but didn't work.
Thanks.
Upvotes: 2
Views: 747
Reputation: 600006
Firestore security rules follow the Google RE2 format for regular expressions.
This means you can define a non-capturing group for your match, and flag that group to use case-insensitive matching with:
allow write: if request.resource.data.str.matches("(?i:^[a-z0-9]+)$");
Of course you can also simply expand the character group to include both uppercase and lowercase ASCII characters:
allow write: if request.resource.data.str.matches("^[a-zA-Z0-9]+$");
Upvotes: 3