Skip to content

Instantly share code, notes, and snippets.

@wyattschwanbeck
Last active May 25, 2022 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wyattschwanbeck/dc9936810acb952e598b043c94c15d4a to your computer and use it in GitHub Desktop.
Save wyattschwanbeck/dc9936810acb952e598b043c94c15d4a to your computer and use it in GitHub Desktop.
Regex for windows file parsing, matching, and validation.
//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