-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregex_tester.py
More file actions
37 lines (25 loc) · 791 Bytes
/
regex_tester.py
File metadata and controls
37 lines (25 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
'''
regex_tester.py - Interactively test a regex for matching properties.
Author: Eric Saunders
December 2010
'''
import re
#regex = r'.*your face(?P<num>\d+)'
#regex = r'^DataOut/(?P<site>\w{3})/(?P<timeInterval>\d+)/(?P<key>[a-z_.]+)/$'
#regex = r'.*href=(\d+\.log)'
#regex = r'^telemetry/find /(?P<site>[a-zA-Z_0-9]+)/$'
#regex = r'log_bfin_mres[a-zA-Z_0-9]+.txt$'
regex = r'[\d]{1,3}$'
print "Regex: '%s'" % regex
pattern = re.compile(regex, re.IGNORECASE)
while (True):
string = raw_input('>')
match = re.match(pattern, string)
#matches = re.findall(pattern, string)
if match:
print "Matched"
print "Unnamed groups:", match.groups()
print "Named groups:", match.groupdict()
else:
print "No match."