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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
^\\(\\[\w-]+){1,}(\\[\w-()]+(\s[\w-()]+)*)+(\\(([\w-()]+(\s[\w-()]+)*)+\.[\w]+)?)?$
Description
Validates UNC Paths, with or without files. Does not validate on shares ($) or local files (c:\xxx). Thanks to Erlend Oftedal for helping me out with this one!
Matches
\\server\directory\ | \\server\directory with space | \\server\directory1\directory2\file1.xxx
Non-Matches
c:\directory | c:\directory\file.xx | \\server\\directory\file.xx.xx
Author Rating: The rating for this expression. Knut Hamang
Source
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Doesn't Match FQDN
Name: Chris
Date: 10/22/2007 12:34:15 PM
Comment:
Your expression does not match a fully qualified domain name such as this. "\\Server.Domain\Folder\


Title: modified
Name: micah
Date: 11/11/2005 4:52:33 PM
Comment:
just wanted to thank you for the expression... I have modified it a bit though and wanted to share. 1) I wanted the share portion and the path portion to be captured into registers. (ie. (\\server\share)(\folder1\folder2\file.exe) 2) I needed to allow hidden shares (ie. \\server\share$). 3) Trailing slashes are now allowed. (ie. \\server\share$\folder\) 4)I noticed that some valid folder name characters were not allowed in the current expression and so rather than adding the valid characters, I have modified it to restrict the use of non-valid characters. (ie. \\server\share$\folder.1\folder.2\!folder 3\) ^(\\\\[\w-]+\\[^\\/:*?<>|""]+)((?:\\[^\\/:*?<>|""]+)*\\?)$ one thing I thought about (but decided it was unimportant for my project) was specifically capturing the file name to another register, but there would be no way to distinguish between a folder name and a file with no extension.


Title: Spaces updated
Name: Knut Hamang
Date: 12/6/2004 10:01:01 AM
Comment:
Added support for spaces and paranthese.


Title: Spaces
Name: mudasser
Date: 10/7/2004 9:41:08 AM
Comment:
Its a very nice expression but it seems to be working only with share names that have no spaces how about modifying it to allow spaces, for exampe \\myserver\my share\my folder\my file.txt It will be a great help for me.


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