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
regex to valid filepath
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

VulpesRank #55 · 29.2K reputationPosted Aug 5, 2013, 8:46 AM EDT
string regExp = @"^(?:[A-Za-z]\:|\\)(\\[a-zA-Z_\-\s0-9\.]+)+(\.\w+)?$";
David SmithRank #999 · 2K reputationPosted Aug 5, 2013, 1:00 PM EDT
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
VulpesRank #55 · 29.2K reputationPosted Aug 5, 2013, 1:46 PM EDT
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\.]+)+\\$";