Vikram Kamath

April 12, 2006

Regular Expression for folder paths

Filed under: Programming — Vikram @ 13:15

I have been looking for a regular expression that allowed me to validate a folder path on a local machine or a shared directory path using UNC with server name or UNC with IP Address. I did find a regular expression on But it didn’t seem to be solving my purpose. So I went about modifying it. I ended up creating different one. Many of you may have done this already. But this was a small exercise on my part to get to build a regular expression. So here it is.

Regular Expression: ^((([a-zA-Z]:)(\\{2}[a-zA-Z]+)(\\{2}\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))(?=(\\(\w[\w ]*)))(\\\w[\w ]*)*)$

Matches: c:\folder one\folder2\folder 3 , \\remoteMachine\folder1, \\\folder 1\folder2Non Matches: c:\\folder one c:folder 1, c:\folder 1\\folder 2, \remoteMachine\folder 1, \\remoteMachine\\folder 1, \\remoteMachine\folder 1\\folder2, \\\\folder 1, \\\folder 1\\folder2

Hope this helps anyone who needs to use it.


1 Comment »

  1. Really helped……

    Comment by HUbert — December 18, 2008 @ 18:47

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Create a free website or blog at

%d bloggers like this: