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))
已给提示: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挑战第三题
- pythontip 挑战python (1-5)
- Python 编程挑战
- Python3 学习第三弹:异常情况如何处理?
- python学习笔记-Day02 -第三部分 浅拷贝和深拷贝
- python 网络编程第三版
- Python学习笔记-Day03 -第三部分(迭代器和生成简介)
- [第三弹]Python正则表达式基础
- MIT Python 第三课一般代码样式 循环式程序 第15分钟:求16的平方根:4
- python挑战题(转+个人解答)
- 第三部分 python的语句与语法
- pythontip 挑战python 21-30 题解
- python第三站:运动员数据筛选
- Python 挑战过关
- Python菜鸟学习第三课
- [Python]第三课纪要
- 可爱的 Python : Python中的函数式编程,第三部分
- pythontip 挑战python (11-20)
- pythonchallenge.com网站上第三题‘One small letter, surrounded by EXACTLY three big bodyguards on each’的解决方法
- python 将一个目录下word转为txt第三版