Suppose I've a url like :
https://example.com/myproject/index-dev.html?_ijt=hsdlgh8h5g8hh489sajoej&a=102&b=a%20m&c=45&d=all&e=all
or it may be a webpage on localhost like :
localhost:63342/my project/index-dev.html?_ijt=hsdlgh8h5g8hh489sajoej&a=102&b=a%20m&c=45&d=all&e=all
and I've to extract query fields (appearing after '?') from these urls in 2-D array as following :
_ijt | hsdlgh8h5g8hh489sajoej
a | 102
b | a m
c | 45
d | all
e | all
Please do note that in 'b' field, I've replaced '%20' with a space. These fields like _ijt,a,b,c,d,e etc can vary in number and their names eg 'a' can be 'city'. So far I've used regular expression to extract out the part after '?' and then use split("&") method to split the string into multiple strings. Code -
val url=localhost:63342/my project/index-dev.html?_ijt=hsdlgh8h5g8hh489sajoej&a=102&b=a%20m&c=45&d=all&e=all
val pattern="""(http|htpps)([A-Za-z0-9\:\/\%\-\.]*)\?""".r
val temp_url=pattern.replaceFirstIn(url,"")
val fields=temp_url.split("&")
println(fields.foreach(println))
and the output is :
_ijt=hsdlgh8h5g8hh489sajoej
a=102
b=a%20m
c=45
d=all
e=all
But it doesn't seem to be the correct way to do this. Any help ?