I have written this code in scala
val regex = "^(\\w+):\\/{2}(\\w*)\\.?([^\\/]*)([^\\?]*)\\??(.*)?".r
val x = "http://www.google.com/foo/bar/baz.html?x=10&y=20&z=20"
regex.findAllIn(x).matchData.foreach{x=> println(s"${x.group(1)} ${x.group(2)} ${x.group(3)} ${x.group(4)} ${x.group(5)}")
This works very well and I get the desired output of
http
www
google.com
/foo/bar/baz.html
x=10
However I need a way by which I can loop over the last part and generate strings for all parameters like
x=10
y=20
z=30
I am not clear as to how to extract the last part in a recurring way.
I know there are lots of existing regex to parse URLs on the internet ... but I am trying to understand regex and write my own. (just to learn).