首页 > 编程语言 > 详细

Python之re模块

时间:2017-05-11 21:26:56      阅读:224      评论:0      收藏:0      [点我收藏+]

re是一个使用频率很高的模块。

# python2
# -*- coding: utf-8 -*-

import re

str = ABC\\-001
print str

str = rABC\-001
print str

if re.match(r\w{3}\\\-\d{3}, str):
    print good match
else:
    print bad match

src = hello\nworld
print src

if re.match(rhello\nworld, src):
    print good match
else:
    print bad match

if re.match(rhello.world, src):
    print good match
else:
    print bad match

if re.match(rhello.world, src, re.S):
    print good match
else:
    print bad match

src = rhello\nworld
print src

if re.match(rhello\\nworld, src):
    print good match
else:
    print bad match

技术分享

这个例子想说明的是,Python中的字符串如果使用‘r‘前缀,字符串中的内容就是本身,没有转义。

re模块的第一个函数:

re.match(patternstringflags=0)

一个常用的flag是:

技术分享

Python之re模块

原文:http://www.cnblogs.com/gattaca/p/6842778.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!