Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- def test_regular_expression(regex, test_string) :
- pattern = re.compile(r'' + regex )
- match = pattern.match(test_string)
- if match :
- try :
- return match.group(1)
- except :
- print('Match found but no substring returned')
- return ''
- else:
- print(regex, 'does not match', string)
- return ''
- auth_log_line = 'Mar 16 11:58:13 users20 sshd[12041]: Accepted password for users257 from 65.96.149.57 port 60695 ssh2'
- regex_time = '(d+:d+:d+)'
- print('regex_time', regex_time, 't returned ', test_regular_expression(regex_time, auth_log_line))
- Traceback (most recent call last):
- File "./test_code.py", line 24, in <module>
- print('regex_time', regex_time, 't returned ', test_regular_expression(regex_time, auth_log_line))
- File "./test_code.py", line 17, in test_regular_expression
- print(regex, 'does not match', string)
- NameError: name 'string' is not defined
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement