automata-labs/TaskC20/solution.py

18 lines
533 B
Python
Raw Permalink Normal View History

2024-12-18 17:56:18 +01:00
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 "<NONE>"
if __name__ == "__main__":
for line in sys.stdin:
stripped_line = line.strip()
print(extract_phone_number(stripped_line))