python电话号码对应的字符组合_Python3 在字符串中提取字母+数字组合微信账号、电话等 - pytorch中文网...
今天處理數據要提取字符串中的微信,字符串中包含中文英文Emoji,標點符號等。
python 提取字符串中的電話
提取電話相對簡單,多個電話也可以提取
import re
desstr = "視頻同款18588888888微信同步"
phone = re.findall('(13\d{9}|14[5|7]\d{8}|15\d{9}|166{\d{8}|17[3|6|7]{\d{8}|18\d{9})', desstr)
print(phone)
python提取微信賬號
這里我使用python移除了Emoji,標點符號,換行等,完整代碼如下:
import re
desstr="""視頻同款Emoji Emoji
Emoji:草莓樹莓是姐妹
Emoji:8888888888(注來意)
Emoji日常視頻
分享全國旅行照片!
Emoji私信不回"""
# 過濾除中,英文及數字以外的其他字符
words = re.compile("[^\\u4e00-\\u9fa5^a-z^A-Z^0-9]").sub("-", desstr).replace(":","-").replace(":","-").replace("\n","-").replace("--", "-").replace("--", "-")
# 打印過濾后的數據
print(words)
# 判斷是否包含中文,包含則不是賬號,這里可以自行提前移除中文
def is_chinese(string):
for ch in string:
if u'\u4e00' <= ch <= u'\u9fff':
return True
return False
# 拆分字符串提取賬號
keywords = re.split("-", words)
print(keywords)
for keyword in keywords:
# 微信號長度為6-20
if len(keyword) > 6 and len(keyword) < 20:
chinese = is_chinese(keyword)
if not chinese:
print(keyword)
原創文章,轉載請注明 :Python3 在字符串中提取字母+數字組合微信賬號、電話等 - pytorch中文網
原文出處: https://www.ptorch.com/news/264.html
問題交流群 :168117787
總結
以上是生活随笔為你收集整理的python电话号码对应的字符组合_Python3 在字符串中提取字母+数字组合微信账号、电话等 - pytorch中文网...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 隐私设置错误您的连接不是私密连接_用小米
- 下一篇: python 函数式 panda_pyt