1. 程式人生 > 其它 >RegEx (14) - 使用字元 \d 包含數字

RegEx (14) - 使用字元 \d 包含數字

技術標籤:RegExpython正則表示式regex

使用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)

結果如下:
在這裡插入圖片描述
如果覺得不錯,就點贊或者關注或者留言~

謝謝~