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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Jul 10, 2013, 6:48 AM EDT
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$";
VulpesRank #55 · 29.2K reputationPosted Jul 9, 2013, 3:46 PM EDT
string regExp = @"^(?:[A-Za-z]\:|\\)(\\[a-zA-Z_\-\s0-9\.]+)+\.xml$";
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 9, 2013, 6:54 PM EDT
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
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 9, 2013, 8:16 PM EDT
Try this
Matches Pattern
-------------------
Non-Matched Pattern
--------------------------
Regards,
Iftikar
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 9, 2013, 8:22 PM EDT
for more detail follow this link
http://www.codeproject.com/Tips/216238/Regular-Expression-to-Validate-File-Path-and-Exten
David SmithRank #999 · 2K reputationPosted Jul 10, 2013, 12:17 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 10, 2013, 12:20 AM EDT
Regards,
Iftikar
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 10, 2013, 12:21 AM EDT
Regards,
Iftikar
VulpesRank #55 · 29.2K reputationPosted Jul 10, 2013, 12:30 AM EDT
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 HussainRank #423 · 5.9K reputationPosted Jul 10, 2013, 12:34 AM EDT
Yes you are right, it should be like this
Regards,
Iftikar
David SmithRank #999 · 2K reputationPosted Jul 10, 2013, 6:29 AM EDT
var regExp = @"^(?:[\w]\:|\\)(\\[a-z_\-\s0-9\.]+)+\.(xml|)$";
string fileN = @"C:\Temp\Run5.xml";
Regex regex = new Regex(regExp);
if (regex.IsMatch(fileN))
{
}
else
{
}
David SmithRank #999 · 2K reputationPosted Jul 10, 2013, 6:51 AM EDT