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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
^((([a-zA-Z]:)|(\\{2}\w+)|(\\{2}(?:(?:25[0-5]|2[0-4]\d|[01]\d\d|\d?\d)(?(?=\.?\d)\.)){4}))(\\(\w[\w ]*)))
Description
Regex to match valid folder paths. can be local, UNC with server name, or UNC with IP address
Matches
c:\ds\dsfsdf | \\192.168.14.118\23423 | \\fsdf\23423
Non-Matches
c:\ | \\192.168.12.114 | \\fff
Author Rating: The rating for this expression. John Conwell
Source Put together from several patterns in regexlib
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: Here's the better version
Name: swingnchad
Date: 6/23/2011 2:41:41 PM
Comment:
^((([a-zA-Z]:)|(\\{2}\w+[-\w+]*)|(\\{2}(?:(?:25[0-5]|2[0-4]\d|[01]\d\d|\d?\d)(?(?=\.?\d)\.)){4}))(\\(\w[\s*\w]*)))


Title: This version works with spaces and dashes
Name: swingnchad
Date: 6/23/2011 2:39:40 PM
Comment:
I modified it to accept folder names with spaces, and dashes in the computer/server name.


Title: Doesn't work with spaces
Name: swingnchad
Date: 6/23/2011 12:05:54 PM
Comment:
Doesn't match this valid path: \\somepc\c\Documents and Settings\someuser The spaces in the folder name mess it up


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