aboutsummaryrefslogtreecommitdiff
path: root/challenge-110/colin-crain/python/ch-1.py
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2021-05-02 09:11:13 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2021-05-02 09:11:13 +0100
commit1e387fae1cd65bbb26cda9b918684adafd507452 (patch)
tree9112f8bc1a91daea62aa1a2caaa84c903586e92b /challenge-110/colin-crain/python/ch-1.py
parent24d00718ffaca48c58ac87d40a8689a3eb3c3589 (diff)
downloadperlweeklychallenge-club-1e387fae1cd65bbb26cda9b918684adafd507452.tar.gz
perlweeklychallenge-club-1e387fae1cd65bbb26cda9b918684adafd507452.tar.bz2
perlweeklychallenge-club-1e387fae1cd65bbb26cda9b918684adafd507452.zip
- Added solutions by Colin Crain.
Diffstat (limited to 'challenge-110/colin-crain/python/ch-1.py')
-rw-r--r--challenge-110/colin-crain/python/ch-1.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/challenge-110/colin-crain/python/ch-1.py b/challenge-110/colin-crain/python/ch-1.py
new file mode 100644
index 0000000000..7c381f1c37
--- /dev/null
+++ b/challenge-110/colin-crain/python/ch-1.py
@@ -0,0 +1,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