- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRegex.py
More file actions
Latest commit
54 lines (47 loc) · 1.96 KB
/
Copy pathRegex.py
File metadata and controls
54 lines (47 loc) · 1.96 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# practise regex
importre
strs= [
"8144658695",
"812 673 5748",
"812 453 6783",
"812-348 7584",
"(617) 536 6584",
"834-674-8595",
"(834 674 8595",
]
forstr1instrs:
s=''
match=re.match(r'(\((?P<ac1>\d{3})\)|(?P<ac2>\d{3}))(\s*|-)(?P<m3>\d{3})(\s*|-)(?P<l4>\d{4})',str1)
ifmatch:
# print match.groups(), match.group("last")
s= (match.group("ac1") ormatch.group("ac2")) +' '+match.group("m3") +' '+match.group("l4")
prints
else:
print"Does not match: ", str1
infos= [
'Zaphod, Beeble, 23/12/1994',
'Dent, Arthur, 05/04/1993',
'Feynman, Richard, 18/02/1956'
]
forinfoininfos:
newDate=''
match=re.search(r'(?P<month2>\d{2})/(?P<date2>\d{2})/(?P<year4>\d{4})',info)
newDate=match.group('date2') +'/'+match.group('month2') +'/'+match.group('year4')[2:]
printnewDate
text="""a@b.com A towel, @f.com it says, is about the most massively useful thing an
interstellar hitchhiker can have. Partly it has great practical value
- you can wrap it around you dent@vogon.com for warmth as you bound across the cold
moons of Jaglan Beta; you can lie on it on the brilliant marble-sanded
beaches of Santraginus V, foo@bar.bar.com inhaling the heady sea vapours; you can
sleep under it beneath the stars which shine so redly on the desert
world of Kakrafoon; use it john.smith@blah.org to sail a mini raft down the slow heavy
river Moth; wet it for use in hand-to- hand-combat; wrap it round your
head to ward off glom@flop.net noxious fumes or to avoid the gaze of the Ravenous
Bugblatter Beast of Traal (a mindboggingly stupid animal, it assumes
that if you can't see it, it can't see you - daft as a bush, but very
ravenous); you can wave your towel in emergencies as a distress
signal, and of course dry yourself off with it if it still seems to be
clean enough."""
# get all the email address
forminre.finditer(r'\b\w[\w\d_-]*(\.\w[\w\d_-]*)*@(\w+\.)+\w+\b', text):
printm.group(0)# entire match