blob: 7c381f1c37908d4689e058e7d8f6055b057b24a4 (
plain)
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
|
#!/usr/bin/env python3
#
#
# phone-block.py
#
# Valid Phone Numbers
# Submitted by: Mohammad S Anwar
# You are given a text file.
#
# Write a script to display all valid phone numbers in the given text file.
#
# Acceptable Phone Number Formats
# +nn nnnnnnnnnn
# (nn) nnnnnnnnnn
# nnnn nnnnnnnnnn
#
# Input File
# 0044 1148820341
# +44 1148820341
# 44-11-4882-0341
# (44) 1148820341
# 00 1148820341
#
# Output
# 0044 1148820341
# +44 1148820341
# (44) 1148820341
#
#
#
# © 2021 colin crain
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
import re
f = open("phone-numbers.txt", "r")
for line in f:
pn = re.search(r"((?:\d{4}|\(\d\d\)|\+\d\d)\s\d{10}(?!\d))", line)
if pn != None:
print('{0:>16s}'.format(pn.group()))
f.close
|