您的位置:首页 > 编程语言 > Python开发

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: