-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
32 lines (30 loc) · 994 Bytes
/
test.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
import rejex
from rejex import Rejex, Static
rejex_test = (
Rejex()
.zero_or_one(
Rejex()
.literal("+")
.one_or_more(
Static.any_number()
)
.compile()
)
.zero_or_one(Static.literal(" "))
.zero_or_one(Static.literal("("))
.n_number_times(3, Static.any_number())
.zero_or_one(Static.literal(")"))
.zero_or_one(Static.literal(" "))
.n_number_times(3, Static.any_number())
.zero_or_one(Static.alternative(Static.literal("-"), Static.literal(" ")))
.n_number_times(4, Static.any_number())
.compile()
)
rejex.test_regex(rejex_test, "+1 (123) 123 4567") #True
"""
-------------------------------
regex_pattern='(\+(\d)+)? ?(\()?(\d){3}(\))? ?(\d){3}((-| ))?(\d){4}'
string='+1 (123) 123 4567'
match=True
-------------------------------
"""