Spaces:
Sleeping
Sleeping
File size: 891 Bytes
ea9ca44 | 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 |
import re
PHONE_REGEX = r"(?:\+?(\d{1,3}))?[-. (]*(\d{2,5})[-. )]*(\d{2,5})[-. ]*(\d{2,5})(?:[-. ]*(\d{1,4}))?"
test_cases = [
# Should match
"+919876543210",
"+91-9876543210",
"9876543210",
"123-456-7890",
"+1 (123) 456-7890", # Parentheses not handled currently
"09876543210",
"+91 98765 43210", # Space not handled
"Phone: +91 9876543210",
]
print(f"Regex: {PHONE_REGEX}\n")
for text in test_cases:
print(f"Testing: '{text}'")
# Using the logic from regex_pii.py
phone_matches = re.finditer(PHONE_REGEX, text)
found = None
for match in phone_matches:
p = match.group(0)
# Check length of digits
if len(re.sub(r"\D", "", p)) >= 10:
found = p.strip()
print(f" ✅ Match: {found}")
break
if not found:
print(" ❌ No valid match found")
|