regex - What would be a regular expression that can test if a string is a valid Firebase key? -


i'm writing application allows users input values stored in firebase key.

firebase key requirement:

max size - 768 bytes cannot contain . $ # [ ] / or ascii control characters 0-31 or 127 allows single spaces, not double or more spaces 

how can express regular expression?

assuming 1 byte = 1 character, , since mention ascii, assuming valid characters ascii characters 32 through 126.

"match of these allowed characters, 768 times":

[ !"%&'()*+\,\-\/0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz\^_`abcdefghijklmnopqrstuvwxyz{|}]{768} 

https://regex101.com/r/lq2gj4/2

edit

that didn't work because missed need block consecutive spaces. new suggestion, basic pattern of:

# space, not followed space # or character not followed double-space. # pattern, matched n times, locking start , end of string.  ^( (?! )|[a](?!  )){5}$ 

however, when substitute full character set in...

^( (?! )|[ !"%&'()*+\,\-\/0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz\^_`abcdefghijklmnopqrstuvwxyz{|}](?!  )){1,768}$  # breaks regex101, saying it's large. 

nb. it's easier without regex:

# python example validator  def validate(s):     valid_chars = 'abc123...'      if not (0 < len(s) <= 768): return false     if '  ' in s: return false     char in s: if char not in valid_chars: return false      return true 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -