I am looking for a regex that validates a filepath. Can someone assist me?
Example:
C;\temp\example.txt Incorrect because of ";"
C:\temp\example.txt Correct
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Aug 5, 2013, 12:46 PM
string regExp = @"^(?:[A-Za-z]\:|\\)(\\[a-zA-Z_\-\s0-9\.]+)+(\.\w+)?$";
VulpesPosted Aug 5, 2013, 5:46 PM
So it wouldn't validate c:\temp\ for example.
However, the following would validate paths which don't include a file name:
string regExp = @"^(?:[A-Za-z]\:|\\)(\\[a-zA-Z_\-\s0-9\.]+)+\\$";
David SmithPosted Aug 5, 2013, 5:00 PM
I am looking for a regex that validates if the string has a filename along with the path review below.
Example:
C:\temp\ Incorrect because of ";" Incorrect
C:\temp\example.txt Correct