這篇文章將為大家詳細講解有關python中邊界匹配語法是什么,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
運用邊界匹配練習
代碼演示:
#匹配以數字開頭的單詞 s = 'hello world 1st, 2st' #\b代表單詞開始或者結束,\d代表數字,\w代表有效字符 result = re.findall(r'\b\d\w*', s) print(result) #匹配s結尾單詞 s = 'this is test' #s\b:代表s結尾單詞 result = re.findall(r'\w*s\b', s) print(result) s = 'hello world, this is test' #查找單詞中包含o的單詞 result = re.findall(r'\w*o\w*', s) print(result) #查找在單詞位置的o result = re.findall(r'\Bo\B', s) print(result)
結果:
['1st', '2st'] ['this', 'is'] ['hello', 'world'] ['o']
關于python中邊界匹配語法是什么就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。