如何使用 Python 正則表示式中的萬用字元?


以下程式碼使用 Python 正則表示式 .()dot 字元表示萬用字元,它代表任何字元(換行符除外)。

示例

import re
rex = re.compile('th.s')
l = "this, thus, just, then"
print rex.findall(l)

輸出

它產生此輸出

['this', 'thus']

更新日期:2020-02-20

2K+ 瀏覽

開啟您的 職業

透過完成課程獲得認證

開始
廣告
© . All rights reserved.