N
Neil
Hello:
I am having trouble figuring out how to write a regular expression to
parse our parts of a url.
For example, I am trying to parse the url
http://jammconsulting.com/jamm/page/test/*/*/*/*.html
into several substrings. The URL should begin with
http://jammconsulting.com/jamm/*/*/
and then have a group of parameters in the form */*
and then end with .html
So, for example, this url:
http://jammconsulting.com/jamm/page/products/Brand/Abc.html
Should give me Brand and Abc as parameters.
I wrote this regular expression:
^http://jammconsulting.com/jamm/[^/]+/[^/]+/([^/]+/[^/]+)*\\.html?
It seems to be working fine for most urls, but it barfed on this one:
http://jammconsulting.com/jamm/page/products/Stuff/Bags-&-Luggage/Bags-&-Totes/Backpacks.html
The matcher gives me 1 group with this value: s/Backpacks
I dont understand how that could have happened. I was expecting to
get
two groups:
Stuff/Bags-%26-Luggage
Bags-%26-Totes/Backpacks
Any ideas what went wrong?
Also, is there a way to tell the pattern to further parse the group
into
Stuff and Bags-%26-Luggage separately or should I do that with another
Pattern I apply to the group after I extract it from the main url?
Thanks,
Neil
I am having trouble figuring out how to write a regular expression to
parse our parts of a url.
For example, I am trying to parse the url
http://jammconsulting.com/jamm/page/test/*/*/*/*.html
into several substrings. The URL should begin with
http://jammconsulting.com/jamm/*/*/
and then have a group of parameters in the form */*
and then end with .html
So, for example, this url:
http://jammconsulting.com/jamm/page/products/Brand/Abc.html
Should give me Brand and Abc as parameters.
I wrote this regular expression:
^http://jammconsulting.com/jamm/[^/]+/[^/]+/([^/]+/[^/]+)*\\.html?
It seems to be working fine for most urls, but it barfed on this one:
http://jammconsulting.com/jamm/page/products/Stuff/Bags-&-Luggage/Bags-&-Totes/Backpacks.html
The matcher gives me 1 group with this value: s/Backpacks
I dont understand how that could have happened. I was expecting to
get
two groups:
Stuff/Bags-%26-Luggage
Bags-%26-Totes/Backpacks
Any ideas what went wrong?
Also, is there a way to tell the pattern to further parse the group
into
Stuff and Bags-%26-Luggage separately or should I do that with another
Pattern I apply to the group after I extract it from the main url?
Thanks,
Neil