0

How to parse the following regex:

    char = r" -~"
    min_length = 5
   '[%s]{%d,}' % (chars, min_length)
Tal Nur
  • 19
  • 2

1 Answers1

4

That's an old style format string. The %s and the %d will be replaced with the values of the chars and min_length variables. The resulting string will be "[ -~]{5,}". [ -~] means "A character within the range of space and tilde"*. {5,} means "five or more of the preceding value". All together, the pattern means "five or more printable ascii characters".

(*in other words, anything with ordinal value between 32 and 126: <space> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}.)

Kevin
  • 69,817
  • 12
  • 97
  • 139