1. 程式人生 > 其它 >RegEx (22) - 使用字元[ ] 來尋找範圍中的任何字元

RegEx (22) - 使用字元[ ] 來尋找範圍中的任何字元

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

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

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