I've been testing a regex of mine. The goal is getting a concrete and named url parameter from a website for replacing it.
Now I almost achieved to get the parameter with this regex:
.website.com.+tag=(?P<tagvalue>.+&|.+\s)
This works fine when the tag is at the end but it gets the value for 'tag' with a trailing '&' like 'value&' when it's in the middle.
I want to get the value but not capturing the ampersand. I tried to extract the termination characters out of the named group like this:
.website.com.+tag=(?P<tagvalue>.+)&|\s
but this regex doesn't work. It always gets until end of line. I want:
- Check if there is a '&' character . If it is, capturing the parameter value without '&'
- If 1 is not true and there is not a '&' character, then capture the value until end of line (I think this until a \s, because I'm processing text and the url comes inside it).
You can test the regex with some test text here:
[^&]+?.website.com.+tag=(?P<tagvalue>[^&\s]+). But like Mike said, you're better off using theurlparselibrary