fork download
  1. def match_regex(string):
  2. state = 0
  3. for char in string:
  4. if state == 0:
  5. if char == 'a':
  6. state = 1
  7. else:
  8. return False
  9. elif state == 1:
  10. if char == 'b' or char == 'c':
  11. state = 1
  12. else:
  13. return False
  14. return state == 1
  15.  
  16. print(match_regex("a")) # True
  17. print(match_regex("ab")) # True
  18. print(match_regex("ac")) # True
  19. print(match_regex("abc")) # True
  20. print(match_regex("abcb")) # True
  21. print(match_regex("d")) # False
Success #stdin #stdout #stderr 0.02s 6976KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/Ly2F6q/prog:21:30: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit