str1 = ‘’’
<imag name = “photo” src = “…/public/img/img1.png”/dsd>
<imag name = ‘news’ src = ‘xxx.jpg’ title = ‘news’/sds>
‘’’
pattern = re.compile(‘src = '"[’"]’) #要有空格隔开 才会有输出结果
str2 = pattern.findall(str1)
print(str2)
在没用空格隔开之前一直输出空串是因为写的img标签中的字符串就是用空格隔开的,如果不用空格隔开的话会导致匹配结果失败
在写正则表示式匹配的时候,一定要比照需要匹配的字符串的格式进行匹配,否则是匹配不出来的