在Python中使用正则表达式提取字符串的特定部分

时间:2013-09-22 11:36:13

标签: python regex

我在下面有这样的字符串,我想在imgurl:之后提取网址。你怎么能用Python方便地做?

{ns:"images",k:"5049",mid:"551FC833EDC139718135AA91A46D6B09FE89E85C",surl:"http://www.thewritingnut.com/blog-challenge/az-day-25-yellow-symbolisms/",imgurl:"http://www.thewritingnut.com/wp-content/uploads/2011/04/yellow-rose-800.jpg",oh:"199",tft:"0",oi:"http://www.thewritingnut.com/wp-content/uploads/2011/04/yellow-rose-800.jpg"}

1 个答案:

答案 0 :(得分:0)

在这里,使用正则表达式:

data = '{ns:"images",k:"5049",mid:"551FC833EDC139718135AA91A46D6B09FE89E85C",surl:"http://www.thewritingnut.com/blog-challenge/az-day-25-yellow-symbolisms/",imgurl:"http://www.thewritingnut.com/wp-content/uploads/2011/04/yellow-rose-800.jpg",oh:"199",tft:"0",oi:"http://www.thewritingnut.com/wp-content/uploads/2011/04/yellow-rose-800.jpg"}'

re.search('imgurl:"([^"]+)', data).group(1)