使用python来做正则表达式:
import re
txt = "werew_wer wesdf 23423 !!! ?"
#Return a match at every word character (characters from a to Z, digits from 0-9, and the underscore _ character):
x = re.findall("\w", txt)
print('使用小写字母:',x)
if x:
print("Yes, there is at least one match!")
else:
print("No match")
#Return a match at every NON word character (characters NOT between a and Z. Like "!", "?" white-space etc.):
y = re.findall("\W", txt)
print('使用大写字母:',y)
if y:
print("Yes, there is at least one match!")
else:
print("No match")
字符 \W: Returns a match where the string DOES NOT contain any word characters
结果如下:
如果觉得不错,就点赞或者关注或者留言~
谢谢~