1. 程式人生 > 其它 >RegEx (20) -使用字元 \Z (大寫)

RegEx (20) -使用字元 \Z (大寫)

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

使用python來做正則表示式:

import re

txt = "xcv xfr wfs"

#Check if the string ends with "wfs":
x = re.findall("wfs\Z", txt)
print(x)

if x:
  print("Yes, there is a match!")
else:
  print("No match")

txt_new = "234 2432 sw 543 sdfsd"
y = re.findall("sdf\Z", txt_new) print(y) if y: print("Yes, there is a match!") else: print("No match")

字元 \Z: Returns a match if the specified characters are at the end of the string

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