fork download
  1. import re
  2. def string_match1(tested_string):
  3. return re.fullmatch(r"(?!(?:\S*\s){2})[A-Za-z0-9\s!#$%&'()@_{}-]*", tested_string)
  4.  
  5. def string_match2(tested_string):
  6. return re.match(r"[A-Za-z0-9!#$%&'()@_{}-]*(?: [A-Za-z0-9!#$%&'()@_{}-]*)?$", tested_string)
  7.  
  8. print(bool(string_match1("b ")))
  9. print(bool(string_match2("b ")))
  10. print(bool(string_match1("b ")))
  11. print(bool(string_match2("b ")))
Success #stdin #stdout 0.02s 9468KB
stdin
Standard input is empty
stdout
True
True
False
False