Get string between ampersand or at the end
I have the following possible URLs:
http://google.com/sadfasdfsd&AA=mytag&SS=sdfsdf
http://google.com/sadfasdfsd&AA=mytag
What is the best way in Python to get mytag from the string ~&AA=mytag&~
?
There are two possibilities: &AA=
in between or &AA=
at the end.
Then how do I match these all with regular expressions?
This question is from: Python Get Tags from URL
>>> import re
>>> str = 'http://google.com/sadfasdfsd&AA=mytag&SS=sdfsdf'
>>> m = re.search(r'.*\&AA=([^&]*)\&.*', str)
>>> m.group(1)
'mytag'
But this only works when I have this type of URL:
http://google.com/sadfasdfsd&AA=mytag&SS=sdfsdf