Hi,
I want to use regex to parse a path. Say I want to extract test.zip from /Test/test.zip.
Could you please let me know how to proceed?
Angkar
Hi,
I want to use regex to parse a path. Say I want to extract test.zip from /Test/test.zip.
Could you please let me know how to proceed?
Angkar
Okay. Why?Originally Posted by AngKarUse Path.GetFileName(string). Most of the things you need to parse from a path can be done with the static methods on the Path class.Originally Posted by AngKar
If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein
Just for fun:
should do the trick... that is a file needs to have an extension of 3 characters , and only one extension is allowed.Code:[a-zA-Z0-9]+\.{1}[a-zA-Z0-9]{3}$
If you only want to get zip files you could go with something like:
Code:[a-zA-Z0-9]+\.{1}zip$
This is all assuming the filename is at the end of the line where you will do the regexp check.
If you want to play and test reg. expressions get something like regexp coach ( it's pretty cool ).
But if I was you I'd go with pianorain's advice, its in the framework so use it , instead of writing code that will make people look twice to understand what you want to achieve.
:edit:
Meh, seems like tést.zip wouldn't be valid with those reg. expressions ... now I'm sad .
because the accented e isn't in the characters you specified for the regex. a lot of charsets don't have the accented characters in them, if you match from the last / until the first . then the remainder with wildcards, then any valid character will cause a match.Originally Posted by GanglyLamb
Originally Posted by Jeff Henager
Thanks guys...got it