#!/usr/bin/python3# find phone numbers and email addresses# ./ph_email.py searches for phone numbers and emails in the latest clipboard# entry and writes the matches into matches.txtimport reimport pyperclip# Phone regex overview per line# word boundary# area code +91, 91, 0# optional space# ten numbers# word boundaryfind_phone = re.compile(r'''\b(\+?91|0)?\ ?(\d{10})\b''', re.X)# email regex source : http://www.regexlib.com/REDetails.aspx?regexp_id=26find_email = re.compile(r'''(([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?))''', re.X)text = pyperclip.paste() # retrieve text from clipboardmatches = [] # list to store numbers and emails# ph[1] means second item of the group-wise tuple# which is returned by findall function# same applies to emailfor ph in find_phone.findall(text):matches.append(ph[1])for em in find_email.findall(text):matches.append(em[0])# display number of matchesprint(f"{len(matches)} matches found")# if matches are found add then to fileif len(matches):with open('matches.txt', 'a') as file:for match in matches:file.write(match)file.write('\n')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。