File & Path

Hidden File (Dotfile)

Matches Unix-style hidden files (dotfiles) like .gitignore or .env.

Try it in RegexPro →

Available in

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("^\\.[^.\\s/\\\\][^/\\\\]*$", "");
const input = ".gitignore";
const match = input.match(re);
console.log(match ? match[0] : null);

Uses `String.prototype.match`, which returns the first match or null.

Pattern

regexengine-agnostic
^\.[^.\s/\\][^/\\]*$

Raw source: ^\.[^.\s/\\][^/\\]*$

How it 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

.gitignore

Matches

  • .gitignore

Input

.env.local

Matches

  • .env.local

Input

..

No match

—

Common use cases

  • •File system tools
  • •Git utilities
  • •Config discovery

Related patterns