我们为什么要使用 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']
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言
C++
C#
MongoDB
MySQL
Javascript
PHP