使用python来做正则表达式:
import re
txt = "a ai aii iaii"
#Check if the string contains "ai" followed by 1 or more characters:
x = re.findall("ai+", txt)
print('使用ai+符号:',x)
if x:
print("Yes, there is at least one match!")
else:
print("No match")
#Check if the string contains "i" followed by 1 or more characters:
z = re.findall("i+", txt)
print('使用i+: ',z)
#Check if the string contains "ai" followed by 0 or more characters:
y = re.findall("ai*", txt)
print('使用*符号:',y)
符号 + 表示:匹配前面的子表达式一次或多次
结果如下:
如果觉得不错,就点赞或者关注或者留言~~
谢谢~ ~