匹配字符
import re
s
= 'adawdafA@#!#@!1231cad'
print(re
.findall
('[a-z]',s
))
print(re
.findall
('[0-9]',s
))
print(re
.findall
('[A-Z]',s
))
print(re
.findall
('[a-zA-Z0-9]',s
))
print(re
.findall
('[^a-zA-Z0-9]',s
))
print(len(re
.findall
("[a-zA-Z\u4e00-\u9fa5]",s
)))
输出结果:
['a', 'd', 'a', 'w', 'd', 'a', 'f', 'c', 'a', 'd']
['1', '2', '3', '1']
['A']
['a', 'd', 'a', 'w', 'd', 'a', 'f', 'A', '1', '2', '3', '1', 'c', 'a', 'd']
['@', '#', '!', '#', '@', '!']
转载请注明原文地址:https://tech.qufami.com/read-7879.html