使用Python来使用RegEx:
import re
txt = "The rain in Spain falls mainly in the plain!"
#Check if the string contains "a" followed by exactly two "l" characters:
x = re.findall("al{2}", txt)
print('al{2} 结果: ',x)
if x:
print("Yes, there is at least one match!")
else:
print("No match")
#Check if the string contains "a" followed by exactly one "a" characters:
y = re.findall('a{1}', txt)
print('a{1} 结果:',y)
字符 {n}: n 是一个非负整数。匹配确定的 n 次。
结果如下:
如果觉得不错,就点赞或者关注或者留言~
谢谢~