|
|

楼主 |
发表于 2018-3-22 08:25:54
|
显示全部楼层
我是根据python编程快速上手 那本书的正则这样写的,- -
它的是这样:
import pyperclip
import re
phoneRegex = re.compile(r'''(
(/d{3}|\(\d{3}\))?
(\s|-|\.)
(\d{4})
(\s*(ext|x|ext\.)\s*(\d{2,5}))?
)''',re.VERBOSE)
text = str(pyperclip.paste())
matches = []
for groups in phoneRegex.findall(text):
phoneRegex = '-'.join([groups[1],groups[3],groups[5]])
# if groups[8] != '':
# phoneNum += ' X' + groups[8]
# matches.append(phoneNum)
if len(matches) > 0:
pyperclip.copy('\n'.join(matches))
print('Copied to clipboard:')
print('/n'.join(matches))
else:
print('Not Find') |
|