pikhmj 发表于 2015-7-28 08:32:07

python中RE正则匹配模块的用法若干

# -*- coding:utf-8 -*-
import import reload()
('utf-8')
= [() for in ['this''that']]   # 编译一个匹配模板对象列表,该列表匹配模板编译源来自一个二元列表
= 'Does this text match the pattern?'
print 'Test:'' 'for in :                   # 查找每一个模板对象
    print 'seeking "%s"-->' % if ():            # search返回找到的第一个对象,没有找到则为空
      print "match"()else:
      print "no match"()
    print ()         # findall返回找到所有匹配项组成的列表
    # 正则表达式量词,转义字符,字符,锚钉码另见另章

    # python3中匹配默认unicode.python2中默认ASCII。故匹配中文及特殊字符。Python2需特殊处理。
    # 重新加载sys模块,指定默认utf-8。在目标字符串和模板前都加U即可。
= u"程序员123一2d3程序2b程序员shitd3程序员coders2d3"
= u"程序员"
= ()
= ()
print [1]
页: [1]
查看完整版本: python中RE正则匹配模块的用法若干