参数说明:接收两个参数,
第一个是匹配的规则,
第二个是匹配的目标字符串,
re.search(pattern, string, flags=0)
re.search 扫描整个字符串并返回第一个成功的匹配。
例如:
s = "http://www.1yahoo.com www.foothill.edu"
print(re.search(r'w{3}\.[a-zA-Z]+\.(com|edu|net)',s).group())
#结果:www.foothill.edu
s = "http://www.yahoo.com www.foothill.edu"
print(re.search(r'w{3}\.[a-zA-Z]+\.(com|edu|net)',s).group())
#结果:www.yahoo.com