MCPcopy Create free account
hub / github.com/ndleah/python-mini-project / PhoneNumCheck

Function PhoneNumCheck

ExtractPhoneNumberEmail/PhoneEmailExtraction.py:11–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9
10
11def PhoneNumCheck():
12 # Regular expression for matching phone numbers
13 PhnNumregex = re.compile(
14 r"""
15 (\(?(\+?\d{1,3})\)? # area code
16 [\s_.-]?) # separator or space
17 (\d{3}) # first three digits
18 [\s_.-]? # separator or space
19 (\d{3}) # second three digits
20 [\s_.-]? # separator or space
21 (\d{4,5}) # last four/five digits
22 """,
23 re.VERBOSE,
24 ) # VERBOSE is used to ignore whitespace and comments inside the regex string
25
26 # Loop through the phone numbers found in the text
27 for num in PhnNumregex.findall(text):
28 if num[1] != "":
29 PhoneNum = "(" + num[1] + ")" # Add area code in brackets
30 else:
31 PhoneNum = ""
32 PhoneNum += "-".join([num[2], num[3], num[4]]) # Join the digits with dashes
33 matches.append(PhoneNum)
34
35
36def EmailCheck():

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected