Re: Need help with regular expression to parse URLs
- From: Knute Johnson <nospam@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 10 Aug 2009 11:50:46 -0700
Neil wrote:
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-%26-Luggage/Bags-%26-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
--
Neil Aggarwal, (281)846-8957, www.JAMMConsulting.com
Will your e-commerce site go offline if you have
a DB server failure, fiber cut, flood, fire, or other disaster?
If so, ask about our geographically redundant database system.
There is no way (that I know of) to get two groups without specifying two sets of parentheses in the regex.
--
Knute Johnson
email s/nospam/knute2009/
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
.
- Follow-Ups:
- References:
- Prev by Date: mirror site, j2se documentation
- Next by Date: Re: Junit - "Credible" HTML checker?
- Previous by thread: Need help with regular expression to parse URLs
- Next by thread: Re: Need help with regular expression to parse URLs
- Index(es):
Relevant Pages
|