Re: A little help with regular expressions
- From: "MatsL@xxxxxxxxxxxxxxxxx" <MatsL@xxxxxxxxxxxxxxxxx>
- Date: Tue, 13 Jun 2006 16:45:53 +0200
Hi Larry,
thanks for the fast reply.
Maybe that is a better way to do it. Your way is how I originally did it, but I thought that a precompiled regex could be faster.
I'll keep my original solution for now.
Best regards
Mats Lycken
Larry Lard wrote:
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/would give the parts[snip]
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.
- Follow-Ups:
- Re: A little help with regular expressions
- From: Kevin Yu [MSFT]
- Re: A little help with regular expressions
- From: Jon Skeet [C# MVP]
- Re: A little help with regular expressions
- References:
- A little help with regular expressions
- From: MatsL@xxxxxxxxxxxxxxxxx
- Re: A little help with regular expressions
- From: Larry Lard
- A little help with regular expressions
- Prev by Date: Re: Visual Styles
- Next by Date: Re: Multiple Thread Problem
- Previous by thread: Re: A little help with regular expressions
- Next by thread: Re: A little help with regular expressions
- Index(es):
Relevant Pages
|