I want to parse out a part of URL using regex operation. This might be old question. But I am new to regex and searched so much for my requirement and not able to find it. I know ParseURL can be used here. But my URLs are not properly structured to use that. Suppose my URL is as follows,
url = https://www.sitename.com/&q=To+Be+Parsed+out&oq=Dont+Need+to+be+parsed
Here I want to find out when &q= occurs and parse out until & occurs next. I want to remove + or any special characters in the middle. The output should be,
To Be Parsed out
Also if there is no match, the original URL should be returned.
I have tried the following,
re.search('q=?([^&]+)&',url).group(0)
this returns,
&q=To+Be+Parsed+out&oq=Dont+Need+to+be+parsed
Can anybody help me in parsing this out. Thanks