def _build_regex_range(ws=True, invert=False, exclude=None):
 if (exclude is None):
  exclude = []
 regex = ''
 in_range = False
 last = None
 last_added = None
 def valid_char(char):
  if (char in exclude):
   result = False
  elif ws:
   result = _is_printable(char)
  else:
   result = (_is_printable(char) and (unicodedata.category(char) != 'Zs'))
  if (invert is True):
   return (not result)
  return result
 for c in _get_all_chars():
  if valid_char(c):
   if (not in_range):
    regex += re.escape(c)
    last_added = c
   in_range = True
  else:
   if (in_range and (last != last_added)):
    regex += ('-' + re.escape(last))
   in_range = False
  last = c
 else:
  if in_range:
   regex += ('-' + re.escape(c))
 return regex

def _build_regex_range ( ws = True , invert = False , exclude = None ) : if ( exclude is None ) : exclude = [ ] regex = '' in_range = False last = None last_added = None def valid_char ( char ) : if ( char in exclude ) : result = False elif ws : result = _is_printable ( char ) else : result = ( _is_printable ( char ) and ( unicodedata . category ( char ) != 'Zs' ) ) if ( invert is True ) : return ( not result ) return result for c in _get_all_chars ( ) : if valid_char ( c ) : if ( not in_range ) : regex += re . escape ( c ) last_added = c in_range = True else : if ( in_range and ( last != last_added ) ) : regex += ( '-' + re . escape ( last ) ) in_range = False last = c else : if in_range : regex += ( '-' + re . escape ( c ) ) return regex
build a range regex for a set of characters in utf8 .