1. (?:...) 不想保存括号里匹配项时使用

The (?:...) notation should be fairly popular; with it, you can group
parts of a regex, but it does not save them for future retrieval or use.

>>> re.findall(r'http://(?:\w+\.)*(\w+\.com)',
'http://google.com http://www.google.com http://code.google.com')
['google.com', 'google.com', 'google.com']

2.(?P<name>) and (?P=name)

can use the (?P<name>) and (?P=name) notations together. The former
saves matches by using a name identifier rather than using increasing
numbers, starting at one and going through N, which are then retrieved
later by using \1, \2, ... \N.

>>> re.search(r'\((?P<areacode>\d{3})\) (?P<prefix>\d{3})-(?:\d{4})',
'(800) 555-1212').groupdict()
{'areacode': '', 'prefix': ''}

3.findall() and finditer();

>>> re.findall(r'\w+(?= van Rossum)',
'''
Guido van Rossum
Tim Peters
Alex Martelli
Just van Rossum
''')
['Guido', 'Just']
>>> bool(re.search(r'(?:(x)|y)(?(1)y|x)', 'xy'))
True
>>> bool(re.search(r'(?:(x)|y)(?(1)y|x)', 'yx'))
True

最新文章

  1. 夕甲甲——孔乙己之C++版
  2. PHP文件的读取
  3. 自然语言16_Chunking with NLTK
  4. python thread 多线程
  5. jQuery基础 - 改变CSS样式
  6. 【转】MySQL5安装的图解(mysql-5.0.27-win32.zip)
  7. view的封装
  8. cojs 疯狂的粉刷匠 疯狂的斐波那契 题解报告
  9. linux下使用NFS挂载文件系统
  10. 自己做的demo--关于HashMap
  11. BZOJ1264: [AHOI2006]基因匹配Match
  12. Hash Map (Hash Table)
  13. KMP算法解析
  14. http连接基础类,负责底层的http通信
  15. How to Make a Computer Operating System
  16. Python 字符串转JSON; 先装字典在转JSON; json.dumps(d)
  17. Top PG Clustering HA Solutions for PostgreSQL
  18. CentOS 利用Yum安装mysql后无法启动(MySQL Daemon failed to start.)
  19. 详解MathType中如何更改公式颜色
  20. [翻译] LiquidFloatingActionButton

热门文章

  1. 通过asp.net程序来控制自己开发的windows服务
  2. leetcode:Reverse Linked List
  3. 4 张 GIF 图帮助你理解二叉查找树
  4. word-pattern(mock)
  5. 漫游Kafka入门篇之简单介绍
  6. BZOJ 1176 MOKIA
  7. VIM Ctrl-V Conflict with Windows Paste
  8. Mysql使用大全
  9. PHP基础 CGI,FastCGI,PHP-CGI与PHP-FPM
  10. python练习程序(c100经典例6)