I am looking for a regex that validates a couple of things.
1.Validate is the string is a valid filepath.
2. Validate if the extension has a '.xml' extension.
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 Jul 10, 2013, 10:48 AM
However, the regex in my first post does allow for upper and lower case letters and works fine in this case:
string regExp = @"^(?:[A-Za-z]\:|\\)(\\[a-zA-Z_\-\s0-9\.]+)+\.xml$";
David SmithPosted Jul 10, 2013, 10:51 AM
David SmithPosted Jul 10, 2013, 10:29 AM
var regExp = @"^(?:[\w]\:|\\)(\\[a-z_\-\s0-9\.]+)+\.(xml|)$";
string fileN = @"C:\Temp\Run5.xml";
Regex regex = new Regex(regExp);
if (regex.IsMatch(fileN))
{
}
else
{
}
Iftikar HussainPosted Jul 10, 2013, 4:34 AM
Yes you are right, it should be like this
Regards,
Iftikar
VulpesPosted Jul 10, 2013, 4:30 AM
That would validate some invalid file paths such as this one:
2:\my files\vulpes.xml
As the drive needs to be a letter, the \w needs to be replaced by a-z and A-Z also needs including if you want it to be case insensitive, as in my own effort.
Iftikar HussainPosted Jul 10, 2013, 4:21 AM
Regards,
Iftikar
Iftikar HussainPosted Jul 10, 2013, 4:20 AM
Regards,
Iftikar
David SmithPosted Jul 10, 2013, 4:17 AM
Sanjeeb LenkaPosted Jul 10, 2013, 12:22 AM
for more detail follow this link
http://www.codeproject.com/Tips/216238/Regular-Expression-to-Validate-File-Path-and-Exten
Iftikar HussainPosted Jul 10, 2013, 12:16 AM
Try this
Matches Pattern
-------------------
Non-Matched Pattern
--------------------------
Regards,
Iftikar
Jignesh TrivediPosted Jul 9, 2013, 10:54 PM
hi,
Please refer following link it might help you
http://www.codeproject.com/Tips/216238/Regular-Expression-to-Validate-File-Path-and-Exten
http://www.coderanch.com/t/551777/java/java/Validating-file-path-regex
VulpesPosted Jul 9, 2013, 7:46 PM
string regExp = @"^(?:[A-Za-z]\:|\\)(\\[a-zA-Z_\-\s0-9\.]+)+\.xml$";