posts - 92,  comments - 173,  trackbacks - 36
公告

import re
r=r'(?<=charset=)(.+[[])(?P<groupname1>.*?)[s(bc)k]\("'  #待分析的正则表达式
s=re.subn(r'\[(?![?]).*?\]','',r)  #排除[]
s=re.subn(r'\\\(','',s[0])  #排除\(
s=re.subn(r'\?P<','',s[0])  #排除(?P<
l=re.findall(r'\((?!\?).*?\)',s[0])  #查找所有组
print len(l)  #打印组数

 

该代码已经应用于我的开源项目http://pyretoolkit.appspot.com/

posted on 2009-09-06 16:12 带电作业 阅读(56) 评论(0) 编辑 收藏