I built a regex with capture groups to separate path of a URL:
Regex:
(?:\/)(?:([^\/]*))
So the above regex works as follows:
If the URL path is: /some/url/path
The above regex results in:
Match 1:
Full match: /some
Group 1: some
Match 2:
Full match: /url
Group 1: url
Match 3:
Full match: /path
Group 1: path
This works fine.
But now I also need a regex to parse a URL path with query parameters:
For ex, if the url path is: /some/url/path?name=xyz&age=21&weight=97
The result should be:
Match 1:
Full match: /some
Group 1: some
Match 2:
Full match: /url
Group 1: url
Match 3:
Full match: /path
Group 1: path
Match 4:
Full match: name=xyz
Group 2: name
Group 3: xyz
Match 5:
Full match: age=21
Group 2: age
Group 3: 21
Match 6:
Full match: weight=97
Group 2: weight
Group 3: 97
Just for information: I am using (regex101) for building regex.