正则匹配(Python)
2016-05-26 19:12
288 查看
1. ‘?’
1.10-1 个字符
1.2 放在末尾,两个对等字符之间
对等字符: 所有称得上是括号的字符:左右对称 所有非括号字符: 自对称 最小对等字符匹配 比如<.*?>匹配下文 <<h1>title<h1>> 最小结果只有<h1> <h2> 顺带地,当有多个匹配结果时, m=re.search(...) m.group(N) 返回第N组括号匹配的字符。(只需要一组结果时,用m.group(1)即可) m.group() == m.group(0) == 所有匹配的字符 !! m.groups() == (m.group(1), m.group(2), ...) 注意匹配的组数由模式决定!! m=re.search('[a-z](.*b)(.*c)','abcd') 有两个(...),所以匹配模式是2 即:m.group(): ('b','c') m.group(0) 'abc' m.group(1) 'b' m.group(2) 'c'
2 模式匹配
(?<= ... ) 前约束 (?= ) 后约束 例如 (?<=abc)[a-z]{3}(?=ghi) 匹配 abcdefghi 结果 def
相关文章推荐
- python代码优化
- python 学习day3
- python快速统计一个文件包含的单词数
- Python3对比Python2的改变
- mac版python TAB补全功能
- python中__getAttribute__的用法
- Python字符进度条
- python之面向对象(继承)
- python笔记1 编码
- python编码错误:UnicodeDecodeError: 'utf8' codec can't decode
- 《统计学习方法》-支持向量机SVM学习笔记和python源码
- Python学习笔记之条件、循环和其他语句
- leetcode 145. Binary Tree Postorder Traversal-后续遍历|递归|非递归
- [Python note] Namespaces & scope
- Python 练习 21
- python 练习 17
- python 练习 20
- python 练习 19
- Python 还是用eclipse好
- 【Eclipse+PyDev+wxPython】wxPython的安装注意事项&&安装后Eclipse中仍然报错问题的解决