从字符串(单引号之间的字符)获取子字符串(Python)

从字符串(单引号之间的字符)获取子字符串(Python),python,regex,Python,Regex,这是我当前拥有的字符串: URL = "location.href='agent_specific_listing.php?sid=131184&mls=693010&a=103&site_id=540&page_current=1';" 我试图用单引号拆分子字符串,结果如下: new_url = 'agent_specific_listing.php?sid=131184&mls=693010&a=103&site_id=540&

这是我当前拥有的字符串:

URL = "location.href='agent_specific_listing.php?sid=131184&mls=693010&a=103&site_id=540&page_current=1';"
我试图用单引号拆分子字符串,结果如下:

new_url = 'agent_specific_listing.php?sid=131184&mls=693010&a=103&site_id=540&page_current=1'
我试图使用re和findall,但我得到了空字符串:

print(re.findall(r"\(u'(.*?)',\)", URL)) // printed empty lists
请让我知道我做错了什么。非常感谢

print re.findall(r"\'(.*?)\'", URL)
因为这是您处理单个报价的方式:

\'   matches a literal '
输出:

'agent_specific_listing.php?sid=131184&mls=693010&a=103&site_id=540&page_current=1';

您可以尝试
re.findall(r“”(.*),URL)
和。在单撇号中是否始终只有一个子字符串?由于使用
来分隔字符串文字。你最好描述一下正则表达式中使用的惰性匹配,它总是伴随着性能成本。@Stribizev是的,双引号只是习惯性的。虽然这段代码可能会回答这个问题,但提供关于为什么和/或如何回答这个问题的附加上下文可以提高它的长期价值。
URL = "location.href='agent_specific_listing.php?sid=131184&mls=693010&a=103&site_id=540&page_current=1';"


newURL = URL.split('location.href=')[1]

print(newURL)
'agent_specific_listing.php?sid=131184&mls=693010&a=103&site_id=540&page_current=1';