Re: A little help with regular expressions

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




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
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...)
[snip]

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

.



Relevant Pages

  • Re: mxDateTime function DateFromString gives wrong year
    ... > I'm not convinced that's a bug. ... The slash is not a valid separator for ... This case is a citation from the original post from 2002. ... For my "Nov 2003" inserting a comma doesn't help. ...
    (comp.lang.python)
  • Re: GForth, ANS, and old conventions
    ... punctuation characters (comma, colon, slash, embedded decimal point, ...
    (comp.lang.forth)
  • Re: A little help with regular expressions
    ... Your way is how I originally did it, but I thought that a precompiled regex could be faster. ... assign everything after the comma to ... Look for the last slash. ... Are the static members of the Path class any help here? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: fortran character set
    ... contention is that the members of list-directed IO can be delimited by ... a comma or a slash during input, ... Slash is technically a separator, ...
    (comp.lang.fortran)
  • RE: search and replace using regex
    ... your forward slash is your separator for the regular exp. ... search and replace using regex ... open|| die "Couldn't open file.new ...
    (perl.beginners)