def _validate_regex(pattern, flags):
 with warnings.catch_warnings(record=True) as recorded_warnings:
  warnings.simplefilter('always')
  try:
   re.compile(pattern, flags)
  except re.error as e:
   raise configexc.ValidationError(pattern, ('must be a valid regex - ' + str(e)))
  except RuntimeError:
   raise configexc.ValidationError(pattern, 'must be a valid regex - recursion depth exceeded')
 for w in recorded_warnings:
  if (issubclass(w.category, DeprecationWarning) and str(w.message).startswith('bad escape')):
   raise configexc.ValidationError(pattern, ('must be a valid regex - ' + str(w.message)))
  else:
   warnings.warn(w.message)

def _validate_regex ( pattern , flags ) : with warnings . catch_warnings ( record = True ) as recorded_warnings : warnings . simplefilter ( 'always' ) try : re . compile ( pattern , flags ) except re . error as e : raise configexc . ValidationError ( pattern , ( 'must be a valid regex - ' + str ( e ) ) ) except RuntimeError : raise configexc . ValidationError ( pattern , 'must be a valid regex - recursion depth exceeded' ) for w in recorded_warnings : if ( issubclass ( w . category , DeprecationWarning ) and str ( w . message ) . startswith ( 'bad escape' ) ) : raise configexc . ValidationError ( pattern , ( 'must be a valid regex - ' + str ( w . message ) ) ) else : warnings . warn ( w . message )
check if the given regex is valid .