473,396 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Better path/filename regex?

This is the best I could quickly come up with:

(?<path>[a-z]:\\(?:[^\\]+\\)+)(?<filename>.+?\.[\S]+)

It's certainly too permissive, but I don't *think* it leaves any valid
ones out (I'm sure a counterexample is only seconds away... :) ).
Many thanks if you have a better one...

cdj

Apr 11 '07 #1
3 4294
cdj,

Why use a regular expression for this? Why not use the static methods
on the Path class in the System.IO namespace to do what you want?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"sherifffruitfly" <sh*************@gmail.comwrote in message
news:11**********************@b75g2000hsg.googlegr oups.com...
This is the best I could quickly come up with:

(?<path>[a-z]:\\(?:[^\\]+\\)+)(?<filename>.+?\.[\S]+)

It's certainly too permissive, but I don't *think* it leaves any valid
ones out (I'm sure a counterexample is only seconds away... :) ).
Many thanks if you have a better one...

cdj

Apr 11 '07 #2
The built-in File and Path classes would help you out immensely. They
already have functionality to do this.
This is the best I could quickly come up with:

(?<path>[a-z]:\\(?:[^\\]+\\)+)(?<filename>.+?\.[\S]+)

It's certainly too permissive, but I don't *think* it leaves any valid
ones out (I'm sure a counterexample is only seconds away... :) ).

Many thanks if you have a better one...

cdj

Apr 11 '07 #3
On Apr 11, 2:00 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
cdj,

Why use a regular expression for this? Why not use the static methods
on the Path class in the System.IO namespace to do what you want?
Because I didn't know they had path/filename strippers. For some
reason I thought a .net path was what most people called a path
+filename. I'll totally look again tho - thanks!

cdj

Apr 13 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
by: Reinhold Birkenfeld | last post by:
Hi, the arguments in the previous thread were convincing enough, so I made the Path class inherit from str/unicode again. It still can be found in CVS:...
1
by: Matt | last post by:
In test() method: var path="C:\test\hello.txt"; //returns -1 for path.lastIndexOf("\\"). why?? var pos=path.lastIndexOf("\\"); //return -1 But in showFile() method: We are able to get the...
2
by: Rob Cowie | last post by:
Hi, Given a string representing the path to a file, what is the best way to get at the filename? Does the OS module provide a function to parse the path? or is it acceptable to split the string...
3
by: Xah Lee | last post by:
Split File Fullpath Into Parts Xah Lee, 20051016 Often, we are given a file fullpath and we need to split it into the directory name and file name. The file name is often split into a core...
8
by: rjb | last post by:
Hi! Could somebody have a look and help me to optimize the code below. It may look like very bad way of coding, but this stuff is very, very new for me. I've included just few lines. Regex...
5
by: Jim McGivney | last post by:
In an aspx page I run the following C# code-behind: string filename = null; filename = txtUpload.PostedFile.FileName.Trim(); //save the file...
1
by: André | last post by:
I'm attempting to override a wxHtmlWindow method in order to pre-process the file before displaying it. I'm using a unicode version of wxPython. I don't think my problem are wxPython-specific, but...
4
by: ano | last post by:
Hi, I tried to use to code to get a file name from a file path but it's working in all case. string t12 = "\"C:\\Program Files\\Microsoft SQL Server\\MSSQL.1\\MSSQL\\Binn\\sqlservr.exe";...
12
by: DFS | last post by:
I need to scan various network folders and capture all the filenames and create dates. ======================================================= 1st effort used the typical drive scan cFile =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.