API文档:
re.compile(pattern[, flags])
Compile a regular expression pattern into a regular expression object, which can be used for matching using its match() and search() methods, described below.
The expression’s behaviour can be modified by specifying a flags value. Values can be any of the following variables, combined using bitwise OR (the | operator).
翻译文档:
参数:
pattern:正则表达式字符串
[flags]:标志对正则表达式进行小处理
描述:
方法返回一个正则表达式对象,可直接调用match()和search()方法
例子:
#! /usr/bin/env python
#coding=utf-8
import re
patternRe = re.compile('^AA')
print patternRe.search('AAbbb')
输出:
<_sre.SRE_Match object at 0x016490C8>

本文介绍如何使用Python的re模块编译正则表达式,并通过实例演示了如何利用编译后的正则表达式对象执行搜索操作。

被折叠的 条评论
为什么被折叠?



