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

Python挑战第三题

2016-12-25 23:03 260 查看
原题地址:http://www.pythonchallenge.com/pc/def/equality.html

已给提示:One small letter, surrounded by EXACTLY three big bodyguards on each of its sides.(一个小写字母,被三个大写字母左右包围)

根据经验,给出大字符串在网页源代码注释中!!

一看应该是字符串处理,找被三个大写字母左右包围的小写字母。那就用最方便的正则表达式处理。

import urllib2
import re
f=urllib2.urlopen('http://www.pythonchallenge.com/pc/def/equality.html')
data=f.read()
#reg=re.compile('[a-z]{1}[A-Z]{3}[a-z]{1}[A-Z]{3}[a-z]{1}')
reg=re.compile('[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]')
print ''.join(reg.findall(data))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python 正则表达式