您的位置:首页 > 编程语言 > Python开发

Python_API_String Services_re.compile

2012-04-05 18:11 549 查看
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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息