我們為什麼要在 Python 正則表示式中使用 re.compile() 方法?
re.compile() 方法
re.compile(pattern, repl, string)
我們可以將 正則表示式 模式組合成模式物件,該物件可用於模式匹配。它還可以幫助我們在不重寫的情況下再次搜尋一個模式。
示例
import re
pattern=re.compile('TP')
result=pattern.findall('TP Tutorialspoint TP')
print result
result2=pattern.findall('TP is most popular tutorials site of India')
print result2輸出
['TP', 'TP'] ['TP']
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP