From 8b27cc30c160224d5a558a9b5afc03c4f8f3e358 Mon Sep 17 00:00:00 2001 From: eddie Date: Wed, 18 Dec 2024 17:56:18 +0100 Subject: [PATCH] Solve TaskC20 Snooze... --- TaskC20/solution.py | 17 +++++++++++++++++ TaskC20/test.out | 6 ++++++ 2 files changed, 23 insertions(+) create mode 100644 TaskC20/solution.py create mode 100644 TaskC20/test.out diff --git a/TaskC20/solution.py b/TaskC20/solution.py new file mode 100644 index 0000000..67e29ea --- /dev/null +++ b/TaskC20/solution.py @@ -0,0 +1,17 @@ +import re +import sys + +def extract_phone_number(line: str) -> str: + # The Pattern: + # - Start word-boundary + # - An optional leading zero + # - Two digits followed by a space + # - Then a digit, followed by '-', then three digits, then '-', then three digits + p = re.compile(r'\b([0]?\d{2}\s\d-\d{3}-\d{3})\b') + m = p.search(line) + return m.group(1) if m else "" + +if __name__ == "__main__": + for line in sys.stdin: + stripped_line = line.strip() + print(extract_phone_number(stripped_line)) diff --git a/TaskC20/test.out b/TaskC20/test.out new file mode 100644 index 0000000..f5ee340 --- /dev/null +++ b/TaskC20/test.out @@ -0,0 +1,6 @@ +00 0-000-000 +000 0-000-000 + +061 5-555-553 +61 5-555-553 +