Last active
January 25, 2019 16:26
-
-
Save JustinBeaudry/7ab0d23fa74ca725c264168b31500dab to your computer and use it in GitHub Desktop.
Javascript Path Regex
This file contains hidden or 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
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