>>> import re
>>> re.search(r'FishC','I love FishC.com')
<_sre.SRE_Match object; span=(7, 12), match='FishC'>
匹配IP
>>> import re
>>> re.search(r'[01]\d\d|2[0-4]\d|25[0-5]','188')
<_sre.SRE_Match object; span=(0, 3), match='188'>
# http异常处理:
import urllib.request
re = urllib.request.Request("http://www.fishc.com/ooxx.html")
try:
urllib.request.urlopen(re)
except urllib.error.URLError as e:
print(e.code)
print(e.read())