- 论坛徽章:
- 9
|
新人学习python中
手上是python2的书,环境为Python 2.7.1
书上脚本与输出为:
- #!/usr/bin/env python
- import re
- re_string = "{{{.*?}}}"
- some_string = "this is a string with {{words}} embedded in\
- {{curly brackets}} to show an {{example}} of {{regular expressions}}"
- for match in re.findall(re_string, some_string):
- print "MATCH->", match
- $ ./retest1.py
- MATCH-> words
- MATCH-> curly brackets
- MATCH-> example
- MATCH-> regular expressions
复制代码 ================
实际运行该脚本为无输出
修改后脚本与输出:
- #!/usr/bin/env python
- import re
- re_string = "{{.*?}}"
- some_string = "this is a string with {{words}} embedded in\
- {{curly brackets}} to show an {{example}} of {{regular expressions}}"
- for match in re.findall(re_string, some_string):
- print "MATCH->", match
- $ ./retest1.py
- MATCH-> {{words}}
- MATCH-> {{curly brackets}}
- MATCH-> {{example}}
- MATCH-> {{regular expressions}}
复制代码 ====
这是版本变化造成还是我写错了?
另外:如果输出时候不需要{{}}将查找结果括起来,是否有简单参数直接去除前后括号?
先谢谢 |
|