python中正则表达式的应用
2010-06-16 21:09
507 查看
#!~/python2.5.2/bin/python
Import re
strPattern='^[a-zA-Z/.:]+([0-9]+)[a-zA-Z/.]+$'
strString='http://www.163.com'
m=re.match(strPattern, strString);
if m is not None:
m.group();
'http://www.163.com'
>>> strNum=m.group(1);
>>> strNum
'163'
>>> strOther=m.group(2);
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
strOther=m.group(2);
IndexError: no such group
Import re
strPattern='^[a-zA-Z/.:]+([0-9]+)[a-zA-Z/.]+$'
strString='http://www.163.com'
m=re.match(strPattern, strString);
if m is not None:
m.group();
'http://www.163.com'
>>> strNum=m.group(1);
>>> strNum
'163'
>>> strOther=m.group(2);
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
strOther=m.group(2);
IndexError: no such group
相关文章推荐
- Python高级——正则表达式 re模块 2.高级应用
- python 中 正则表达式 的应用
- python--正则表达式应用
- 学习正则表达式在python中的应用
- python3爬虫之入门和正则表达式,获取IP地址, 隐马尔可夫模型及其在分词中的简单应用
- python全栈开发-re模块(正则表达式)应用(字符串的处理)
- python 正则表达式应用——缩写词扩充
- python应用regex正则表达式模块re
- Python 正则表达式替换应用 (用文本中一部分替换另一部分)
- Python中正则表达式的应用
- python学习之正则表达式应用
- python应用regex正则表达式模块re
- python 3.6 正则表达式的应用(附实例代码)
- Python网页抓取正则表达式应用练习-爬取基金信息
- 正则表达式re中的贪心算法和非贪心算法 在python中的应用
- Python中正则表达式应用
- Python开发基础-Day15正则表达式爬虫应用,configparser模块和subprocess模块
- Python 正则表达式的应用(十二)
- Python 正则表达式高级应用举例
- python基础之正则表达式爬虫应用,configparser模块和subprocess模块