Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
str = "{u'xlink:href': u'http://ip/goform/XmlApi?op=ip&port=0&target=1', u'id': u'1'}" print re.search("/href': u'.*?',/", str)
我正在尝试获取以 http:// 开头并以 target=1 结尾的文本,但我没有得到。我的正则表达式错了吗?
是的,我认为您正在寻找错误的东西(如果您想要的是 url):
#!/usr/bin/env python import re if __name__ == '__main__': s = "{u'xlink:href': u'http://ip/goform/XmlApi?op=ip&port=0&target=1', u'id': u'1'}" m = re.search(r"u'(http://.*?)',", s) print m.group(1)