第四题地址: http://www.pythonchallenge.com/pc/def/equality.html
根据给出的提示,需要在给出的source中找到一个小写字符,左边和右边刚好恰好有且仅有三个大写字符。
import re
import urllib
# urllib to open the website
response= urllib.urlopen("http://www.pythonchallenge.com/pc/def/equality.html")
source = response.read()
data = re.findall(r'<!--(.+?)-->', source, re.S)
response.close()
charList = re.findall(r'[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]', data[0])
print ''.join(charList)
根据上一题的提示,我们继续在html注释的部分找到了需要解析的代码。
[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]
意味着,从不是大写字母开始,重复三个大写字母,一个小写字母,再三个大写字母,之后再没有大写字母。 符合题目的要求。
最终得到结果是linkedlist。