0
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)

I'm trying to get the text that starts with http:// and ends with target=1 but I'm getting None. Is my regex wrong?

Takkun
  • 6,131
  • 16
  • 52
  • 69

1 Answers1

1

Yes I think you're searching for the wrong thing (if what you want is the 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)
cadizm
  • 896
  • 7
  • 4