Last active
May 25, 2022 22:31
-
-
Save wyattschwanbeck/dc9936810acb952e598b043c94c15d4a to your computer and use it in GitHub Desktop.
Regex for windows file parsing, matching, and validation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://www.codeproject.com/Tips/216238/Regular-Expression-to-Validate-File-Path-and-Exten?msg=5202231#xx5202231xx | |
//Credit Bryian Tan 2012 | |
^(?:[\w]\:|\\)(\\[a-z_\-\s0-9\.]+)+\.(txt|gif|pdf|doc|docx|xls|xlsx)$ | |
//Adapted and expanded variations | |
//Added capital letters | |
(?:[\w]\:|\\)(\\[A-Za-z_\-\s0-9\.]+)+\.(txt|gif|pdf|doc|docx|xls|xlsx) | |
//Adapted to forward slashes and added capital letters to match | |
(?:[\w]\:|\/)(\/[A-Za-z_\-\s0-9\.]+)+\.(txt|gif|pdf|doc|docx|xls|xlsx) | |
//Date matching regex 1900-2999 dd/mm/yyyy | |
(3[0-1]|[0-2][0-9])\/((0[0-9])|(1[0-2]))\/[0-2][0-9][0-9][0-9] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment