RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Expressions by User

   Displaying page 1 of 1 pages; Items 1 to 2
Title Test Details Windows Drive Letter & UNC Path
Expression
^((\\\\[a-zA-Z0-9-]+\\[a-zA-Z0-9`~!@#$%^&(){}'._-]+([ ]+[a-zA-Z0-9`~!@#$%^&(){}'._-]+)*)|([a-zA-Z]:))(\\[^ \\/:*?""<>|]+([ ]+[^ \\/:*?""<>|]+)*)*\\?$
Description
This expression was written for C#, and as such you should just be able to drop it in. It matches Windows paths, be they the drive letter version or the UNC version. It was not written to specifically match filenames, but it will in most cases anyway. Be aware that Windows has a maximum path+filename length (260 chars on XP) and this regular expression does not check for this. This has been tested against large datasets.
Matches
C:\Program Files\Test, \\server\share\directory
Non-Matches
c:?Program Files\Lab, \\$erver\sh*re\directory, a:\di:::r
Author Rating: The rating for this expression. Tristan DF Wilson
Title Test Details Windows Filename
Expression
^[^ \\/:*?""<>|]+([ ]+[^ \\/:*?""<>|]+)*$
Description
This was written for C# and so you should just be able to drop it into your C# program. Although you can create files with leading and trailing spaces through non-GUI means, the Windows GUI itself eats those spaces if you try to rename the file. For this reason I made the decision to consider file names with leading and trailing spaces invalid. This has been tested against large data sets.
Matches
bla, file.txt, !@#$
Non-Matches
bla , file:txt, /\*?
Author Rating: Not yet rated. Tristan DF Wilson
   Displaying page 1 of 1 pages; Items 1 to 2

Copyright © 2001-2025, RegexAdvice.com | ASP.NET Tutorials