re findall 匹配


import re

str1 = '{"title":"北京美食","url":"http://bj.meituan.com/meishi/"},{"title":"北京香锅烤鱼","url":"http://bj.meituan.com/meishi/c20004/"}'

regex2=re.compile('"url":"(http://bj.meituan.com/meishi/.*?)"}')

hrefarr = regex2.findall(str1)

print(hrefarr)

print(hrefarr[0])

print(hrefarr[1])

regex2=re.compile('"title":"(.*?)","url":"http://bj.meituan.com/meishi')

titlearr = regex2.findall(str1)

print(titlearr)

print(titlearr[0])

print(titlearr[1])

你可能感兴趣的:(re findall 匹配)