Re: A little help with regular expressions
- From: "Larry Lard" <larrylard@xxxxxxxxxxx>
- Date: 13 Jun 2006 07:18:08 -0700
MatsL@xxxxxxxxxxxxxxxxx wrote:
Hi, I saw that some other people posted questions about regular
expressions here so I thought I would do the same.
I'm trying to parse an url to different parts.
I want the file name and path to be two different parts.
To do this I make the assumption that all file names has a '.' in them.
I also want a third part called mode that is appended to the url with a ','.
ie.
/path/url/file.aspx,theMode
would give the parts
path = /path/url
file = file.aspx
mode = theMode
/path/url/,theMode and /path/url,theMode
would give the parts
path = /path/url
file =
mode = theMode
/path/url and /path/url
I assume one of these is meant to be /path/url/
[snip]
would give the parts
path = /path/url
file =
mode =
I've been working with this for a couple of days now I can't get it to
work :\
here is what I have so far (it's really not working, I messed it up
somewhere along the way...)
Unless you have some compelling reason to do this with regex, it seems
to be it would be far more straightforward (and maintainable, and
understandable) to do this:
- Is there a comma? If there is, assign everything after the comma to
mode, and remove everything from the comma onwards
With what remains:
- Look for the last slash. (If there isn't a slash, assign the entire
text to file or path according to whether it does or doesn't contain a
period)
- Is there a period after the last slash?
Yes: Assign everything after the last slash to file, everything up
to but not including the last slash to path
No: Assign everything to path, dropping a trailing slash if one is
there
I haven't checked every case, but this or something like it is surely
more sensible than a superduper one line regex.
OR
Are the static members of the Path class any help here? There's a class
for parsing URLs also I think.
--
Larry Lard
Replies to group please
.
- Follow-Ups:
- Re: A little help with regular expressions
- From: MatsL@xxxxxxxxxxxxxxxxx
- Re: A little help with regular expressions
- References:
- A little help with regular expressions
- From: MatsL@xxxxxxxxxxxxxxxxx
- A little help with regular expressions
- Prev by Date: Re: Database: table field casting problem
- Next by Date: Re: Edit C# ListView
- Previous by thread: A little help with regular expressions
- Next by thread: Re: A little help with regular expressions
- Index(es):
Relevant Pages
|