0

I have created a program that takes text from clipboard and identifies the phone numbers that were on the text. However when the programme is executed, the output shows a list which contains many tuples of the digits of a phone number. I have checked my parenthesis and it seems fine to me but if someone could take a look over it and guide it would be helpful.

#! python3
print('Good evening')
import re,pyperclip
#seperating the numbers
phoneregex=re.compile(r'''
# Number of the form :123-456-7890,123 456 7890,(123) 456-789
(
((\d\d\d)|(\(\d\d\d\)) #1 term
(\s|-) # spacing
\d\d\d #2 term
(\s|-) # spacing
\d\d\d\d)?#last 4 digits
)         #for keeping it as a single group.
''', re.VERBOSE)
print(phoneregex.findall(pyperclip.paste()))



 
  • 1
    `re.findall()` is going to give you the contents of each of those parenthesized groups. Make them *non-capturing groups* instead - `(?:`...`)` instead of `(`...`)`. – jasonharper Oct 03 '20 at 02:25

0 Answers0