RegEx (22) - 使用字元[ ] 來尋找範圍中的任何字元
阿新 • • 發佈:2021-01-17
使用python來做正則表示式:
import re
txt = "teg erwe df 23"
#Check if the string has any characters between a and n:
x = re.findall("[a-n]", txt)
print('[a-n] 結果:',x)
if x:
print("Yes, there is at least one match for characters between a and n!" )
else:
print("No match")
y = re.findall("[o-z]", txt)
print('[o-z] 結果:',y)
字元 [a-n]: Returns a match for any lower case character, alphabetically between a and n
結果如下:
如果覺得不錯,就點贊或者關注或者留言~
謝謝~