我们为什么要在 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