Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear friends i want to validate a path format say
c:\abcFolder through regular expression plz help

What I have tried:

i have tried regular expression like this
^((([a-zA-Z]:)(\\{2}[a-zA-Z]+)(\\{2}\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))(?=(\\(\w[\w ]*)))(\\\w[\w ]*)*)$
Posted
Updated 28-May-17 6:18am
v2
Comments
Maciej Los 26-May-17 9:34am    
Can you explain what you want to achieve? I guess you want to be sure that path is correct (exists, is avalible, etc.). Am i right?

 
Share this answer
 
Comments
srilekhamenon 26-May-17 6:08am    
i want folder path not file path and i also want to exclude the special character from the path which are not allowed in path
F-ES Sitecore 26-May-17 6:20am    
You didn't mention any of that in the question. People aren't mind readers.
srilekhamenon 26-May-17 6:28am    
i have updated my question :)
srilekhamenon 26-May-17 6:10am    
i had tried expression something like this
^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))$ but this is allowing special characters
Use last link to see a nice graph of your RegEx.
I don't know what you expect to match with this RegEx, but it look very wrong.
You should improve your question and describe precisely what you want (and don't want) to match. By the way, the language you use matters too.

Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
 
Share this answer
 
v2

i had tried expression something like this
^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))$ but this is allowing special characters


If you would like to check if path is correct (doesn't contain invalid characters, etc., use Path[^] class. See:
Path.GetInvalidFileNameChars Method (System.IO)[^]
Path.IsPathRooted Method (String) (System.IO)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900