摘要: 背景: 在使用python的过程中,你肯定对转义字符的使用苦恼过,因为有的时候我们需要使用一些特殊符号如”$ * . ^”等的原意,有时候需要被转义后的功能,并且转义字符地使用很繁琐,容易出错,那拯救你的就非re.escape莫属了。 escape(pattern) Escape all non-a 阅读全文
posted @ 2017-09-30 15:09 xiaojinniu425 阅读(11027) 评论(0) 推荐(2) 编辑
摘要: 背景: re.sub是re模块重要的组成部分,并且功能也非常强大,主要功能实现正则的替换。 re.sub定义: sub(pattern, repl, string, count=0, flags=0) Return the string obtained by replacing the leftm 阅读全文
posted @ 2017-09-30 14:57 xiaojinniu425 阅读(585) 评论(0) 推荐(0) 编辑
摘要: 这四个方法是从某个字符串中寻找特定子串或判断某个字符串是否符合某个模式的常用方法。 1、match re.match(pattern, string[, flags]) 从首字母开始开始匹配,string如果包含pattern子串,则匹配成功,返回Match对象,失败则返回None,若要完全匹配,p 阅读全文
posted @ 2017-09-30 14:41 xiaojinniu425 阅读(813) 评论(0) 推荐(0) 编辑