RegEx (24) - 使用[ ] 來檢查string中有沒有數字
阿新 • • 發佈:2021-01-17
使用python來做正則表示式:
import re
txt = "23n sdf 2432 42 sffw"
#Check if the string has any 0, 1, 2, or 3 digits:
x = re.findall("[0123]", txt)
print(x)
if x:
print("Yes, there is at least one match!")
else:
print("No match")
字元[0123]: Returns a match where any of the specified digits (0, 1, 2, or 3) are present
結果如下:
如果覺得不錯,就點贊或者關注或者留言~
謝謝~