-
Notifications
You must be signed in to change notification settings - Fork 2
/
regex.py
36 lines (29 loc) · 1.06 KB
/
regex.py
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
import sys
from time import perf_counter_ns
from pyregexp.engine import RegexEngine
def usage():
print("usage: {} regex test_string1 [test_string2 ...]".format(
sys.argv[0]))
pass
reng = RegexEngine()
if __name__ == "__main__":
if len(sys.argv) == 2 and sys.argv[1] == '--usage' or sys.argv[1] == '--help' or sys.argv[1] == '-u' or sys.argv[1] == '-h':
usage()
exit(0)
else:
if len(sys.argv) < 3:
print("Missing arguments.")
usage()
exit(-1)
regex = sys.argv[1]
print("Regular expression: '{}'".format(regex))
i = 2
while i < len(sys.argv):
test_str = sys.argv[i]
start_time = perf_counter_ns()
res, _ = reng.match(regex, test_str)
stop_time = perf_counter_ns()
print(f'Execution time: {stop_time - start_time} ns.')
print_string = f"'{test_str}' match with the regex" if res == True else f"'{test_str}' doesn't match the given regex"
print(print_string)
i += 1