Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. import re
  2.  
  3. def test_regular_expression(regex, test_string) :
  4. pattern = re.compile(r'' + regex )
  5. match = pattern.match(test_string)
  6. if match :
  7. try :
  8. return match.group(1)
  9. except :
  10. print('Match found but no substring returned')
  11. return ''
  12. else:
  13. print(regex, 'does not match', string)
  14. return ''
  15.  
  16. auth_log_line = 'Mar 16 11:58:13 users20 sshd[12041]: Accepted password for users257 from 65.96.149.57 port 60695 ssh2'
  17.  
  18. regex_time = '(d+:d+:d+)'
  19. print('regex_time', regex_time, 't returned ', test_regular_expression(regex_time, auth_log_line))
  20.  
  21. Traceback (most recent call last):
  22. File "./test_code.py", line 24, in <module>
  23. print('regex_time', regex_time, 't returned ', test_regular_expression(regex_time, auth_log_line))
  24. File "./test_code.py", line 17, in test_regular_expression
  25. print(regex, 'does not match', string)
  26. NameError: name 'string' is not defined
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement