Regular Expression Discussion
2015-06-08 12:08
363 查看
1. Pattern .*? will match all the text appended by for only once and return result:
Example:
pattern = r'[0-9].*?'
text = r'9800abcd'
match = re.findall(pattern, text)
Result:
match
Out[6]: ['9', '8', '0', '0']
2. Pattern .+? will match all the text appended by for two times and return result:
Example:
pattern = r'[0-9].+?'
text = r'9800abcd'
match = re.findall(pattern, text)
Result:
match
Out[8]: ['98', '00']
3. About the Matching Result of findall:
@1.当给出的正则表达式中带有多个括号时,列表的元素为多个字符串组成的tuple,tuple中字符串个数与括号对数相同,字符串内容与每个括号内的正则表达式相对应,并且排放顺序是按括号出现的顺序。
@2.当给出的正则表达式中带有一个括号时,列表的元素为字符串,此字符串的内容与括号中的正则表达式相对应(不是整个正则表达式的匹配内容)。
@3.当给出的正则表达式中不带括号时,列表的元素为字符串,此字符串为整个正则表达式匹配的内容。
quoted from : http://developer.51cto.com/art/201003/188828.htm
Example:
pattern = r'[0-9].*?'
text = r'9800abcd'
match = re.findall(pattern, text)
Result:
match
Out[6]: ['9', '8', '0', '0']
2. Pattern .+? will match all the text appended by for two times and return result:
Example:
pattern = r'[0-9].+?'
text = r'9800abcd'
match = re.findall(pattern, text)
Result:
match
Out[8]: ['98', '00']
3. About the Matching Result of findall:
@1.当给出的正则表达式中带有多个括号时,列表的元素为多个字符串组成的tuple,tuple中字符串个数与括号对数相同,字符串内容与每个括号内的正则表达式相对应,并且排放顺序是按括号出现的顺序。
@2.当给出的正则表达式中带有一个括号时,列表的元素为字符串,此字符串的内容与括号中的正则表达式相对应(不是整个正则表达式的匹配内容)。
@3.当给出的正则表达式中不带括号时,列表的元素为字符串,此字符串为整个正则表达式匹配的内容。
quoted from : http://developer.51cto.com/art/201003/188828.htm
相关文章推荐
- Android自定义无下划线ClickableSapn超链接文本样式
- 一类有关序列的技巧问题
- POJ 1007
- 同步/异步与阻塞/非阻塞的区别
- 以Android Library的方式使用<工程> for <Vitamio >
- U盟微信分享
- linux各个目录内容
- CCIE/CCDE实验考试政策
- Eclipse将引用了第三方jar包的Java项目打包成jar文件的两种方法
- 在Java中调用Python
- poj1163The Triangle(简单DP)
- MYSQL建用户,建库,建表,授权
- 详解JavaScript中的every()方法
- 二叉树
- java高分局之JVM命令参数大全(高级运行时选项)
- CCIE/CCDE笔试考试政策
- 爱加密Android APk 原理解析
- GDB(二) 内存布局
- 暴风影音5免去广告的小技巧
- 搭建Kafka开发环境