Skip to content

Instantly share code, notes, and snippets.

@JustinBeaudry
Last active January 25, 2019 16:26
Show Gist options
  • Save JustinBeaudry/7ab0d23fa74ca725c264168b31500dab to your computer and use it in GitHub Desktop.
Save JustinBeaudry/7ab0d23fa74ca725c264168b31500dab to your computer and use it in GitHub Desktop.
Javascript Path Regex
const isPath = str => /^(\/?[^\/ ]*)+\/?\.\w+$/i.test(str);
isPath('adsasdasd'); // false
isPath('path/to/file'); // false
isPath('path/to/file.txt'); // true
isPath('/path/to/file.txt'); // true
isPath('C:\path\to\file.txt'); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment