Level 3
import re
import os
direct=os.getcwd()
with open(direct+r'\code.txt','r') as file:
code=file.read().replace('\n','')
list1=re.findall(r'[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]',code)#[^A-Z]表示匹配非大写字母1次。([a-z])带圆括号(),表示findall结果只返回[a-z]匹配的字母,不含前后的其他匹配字符
print(''.join(list1))
Level 4
import urllib.request
import re
#number=12345%初始值
number=72758%中途调整一次
while number:
try:
url=f'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing={number}'
response=urllib.request.urlopen(url)#请求网页
number=re.findall('nothing is (\d+)',str(response.read()))[0]#抓取网页内容并匹配提取数字
except Exception:#找不到数字时findall返回空列表[],[][0]抛出异常
print(url)
break