尝试运行此代码时,出现“无效语法”错误,它将突出显示('t'或行中的空格
extractedPhone = phoneRegex.findall(文本)
为什么?仔细检查所有其他(),以确保所有内容均已打开和关闭,将文本重命名为示例,不确定发生了什么!
此操作的目的是仅通过复制文件然后运行它来从PDF搜索电话号码和电子邮件。
谢谢
#! Python3
import re
import pyperclip
#create a regex for phone numbers
phoneRegex = re.compile(r'''
((\d\d\d)|(\(\d\d\d\)))? #area code optional
(\s | -) #first seperator
\d\d\d #three digits
(\s | -) #second seperator
\d\d\d\d #last four digits
(((ext(\.)?\s)|x) #ext. 12345
(\d{2,5))? #ext optional number
''', re.VERBOSE)
#create a regex for email addresses
emailRegex = re.compile('''(
[A-Za-z0-9-_+.]+ #name part (AZaz+_-.)
@ #@
[A-Za-z0-9-_+.]+ #domain
)''' re.VERBOSE)
#get text off the clipboard
text = pyperclip.paste()
#extract the email / phone from this text
extractedPhone = phoneRegex.findall (text) #here is the issue line
extractedEmail = emailRegex.findall (text)
allPhoneNumber = []
for numbers in extractedPhone:
allPhoneNumbers.append(phoneNumber[0])
print (extractedPhone)
print (extractedEmail)
答案 0 :(得分:-1)
在此行上
emailRegex = re.compile('''(
[A-Za-z0-9-_+.]+ #name part (AZaz+_-.)
@ #@
[A-Za-z0-9-_+.]+ #domain
)''', re.VERBOSE) # you missed a comma here after triple-quote.