python中re.compile函数的使用

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python中re.compile函数的使用相关的知识,希望对你有一定的参考价值。

参考技术A python通过re模块提供对正则表达式的支持。使用re的一般步骤是

1.先使用re.compile()函数,将正则表达式的字符串形式编译成Pattern实例。

2.然后使用Pattern实例处理文本并获得匹配结果(一个match实例),最后使用Match实例获得信息,进行其他的操作。

举一个简单的例子,在寻找一个字符串中所有的英文字符:

import re

pattern = re.compile(‘[a-zA-Z]')

result = pattern.findall('as3SiOP')

print result

以上是关于python中re.compile函数的使用的主要内容,如果未能解决你的问题,请参考以下文章

python 中的 re.compile 函数(转)

Python re模块 正则表达式之compile函数

Python3中正则模块re.compilere.match及re.search函数用法详解

python 正则(re.compile()/re.findall())

python中,有关正则表达式re函数:compilematchsearchfindall

python的“re.compile”有啥作用?