RegEx (14) - 使用字元 \d 包含數字
阿新 • • 發佈:2021-01-16
使用python來做正則表示式:
import re
txt = "12 324 rain"
#Check if the string contains any digits (numbers from 0-9):
x = re.findall("\d", txt)
print('x 結果: ',x)
if x:
print("Yes, there is at least one match!")
else:
print("No match" )
txt_new = 'wer asdfw rew sddf'
y = re.findall("\d", txt_new)
print('y 結果:',y)
if y:
print("Yes, the string has digits")
else:
print("No, there is no any digits in the string")
字元 \d: Returns a match where the string contains digits (numbers from 0-9)
結果如下:
如果覺得不錯,就點贊或者關注或者留言~