phoneRegex = re.compile(r'''(
(\+)?
(\s)?
(91)?
(\s)?
(\d{5})
(\s)?
(\d{5})
)''', re.VERBOSE)
You are finding the capture groups and joining them in phoneNum
now the capture groups (\+)
,(\s)
,(91)
,(\s)
,(\d{5})
,(\s)
, and (\d{5})
together make up a phone number.
and the large capture group ( (\+)? (\s)? (91)? (\s)? (\d{5}) (\s)? (\d{5}) )
also captures the phone number. Hence a phone number is printed twice.
3
solved Automate the Boring Stuff: Phone number and email extractor [closed]