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
Printable View
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?Quote:
Originally Posted by AngKar
Use 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.Quote:
Originally Posted by AngKar
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 :D.
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.Quote:
Originally Posted by GanglyLamb
Thanks guys...got it :)