python 正则之提取字符串中的汉字,数字,字母
生活随笔
收集整理的這篇文章主要介紹了
python 正则之提取字符串中的汉字,数字,字母
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
python 正則之提取字符串中的漢字,數字,字母
#\d 匹配一個數字字符。等價于 [0-9] #\D 匹配一個非數字字符。等價于 [^0-9]#過濾字符串中的英文與符號,保留漢字 import re st = "hello,world!!%[545]你好234世界。。。" ste = re.sub("[A-Za-z0-9\!\%\[\]\,\。]", "", st) print(ste)#從字符串中提取數字 totalCount = '100abc' totalCount = re.sub("\D", "", totalCount) print(totalCount)#從字符串中提取字母字符串 import re st = "hello,world!!%[545]你好234世界。。。" result = ''.join(re.findall(r'[A-Za-z]', st)) print(result) 你好世界 100 helloworldposted on 2018-07-06 20:59 luoganttcc 閱讀(...) 評論(...) 編輯 收藏
總結
以上是生活随笔為你收集整理的python 正则之提取字符串中的汉字,数字,字母的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 正则学习笔记
- 下一篇: python TF-IDF