Regex to check for valid URL in Firebase Security Rule -
i'm trying implement firebase security rule check if valid url using regex. here sample of url :
https://firebasestorage.googleapis.com/andtherestisjustthepartafteriuploadedintofirebasestorage
i used regex check:
"imageurl": { ".validate": "newdata.val().matches(/((([a-za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[a-za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[a-za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/)" }
however, i'm getting error @ line 26: invalid escape: '\+'.
any ideas?
its not necessary escape +
in regex class
, instead use this:
[-+=&;%@.\w_]
i see syntax errors in pattern, character should escaped athors should not, pattern should :
/((([a-za-z]{3,9}:(?:\\/\\/)?)(?:[-;:&=+\\$,\\w]+@)?[a-za-z0-9.-]+|(?:www.|[-;:&=+\\$,\\w]+@)[a-za-z0-9.-]+)((?:\\/[%+~\\/.\\w-_]*)?\\??(?:[-+=&;%@.\\w_]*)#?(?:[\\w]*))?)/
but i'm not sure of logic of pattern, suggest read more information firebase security rules regular expressions
Comments
Post a Comment