Hidden File (Dotfile) in JS
Matches Unix-style hidden files (dotfiles) like .gitignore or .env.
Try it in the JS tester →Pattern
regexJS
^\.[^.\s/\\][^/\\]*$JavaScript / ECMAScript code
jsJavaScript
const re = new RegExp("^\\.[^.\\s/\\\\][^/\\\\]*$", "");
const input = ".gitignore";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
How the pattern works
`^\.` requires leading dot. `[^.\s/\\]` requires the next character to not be another dot, whitespace, or slash. `[^/\\]*$` allows any additional non-slash characters.
Examples
Input
.gitignoreMatches
.gitignore
Input
.env.localMatches
.env.local
Input
..No match
—