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 matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
pyPython
import re
pattern = re.compile(r"^\.[^.\s/\\][^/\\]*$")
input_text = ".gitignore"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
goGo
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^\.[^.\s/\\][^/\\]*$`)
input := `.gitignore`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
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
.gitignoreMatches
.gitignore
Input
.env.localMatches
.env.local
Input
..No match
—Common use cases
- •File system tools
- •Git utilities
- •Config discovery
Related patterns
.env File Key-Value Line
File & PathParse KEY=value lines from .env config files, handling quoted values and trailing comments.
Unix File Path
File & PathMatches absolute Unix/Linux file paths.
Dockerfile ENV Instruction
File & PathMatch Dockerfile `ENV KEY=value` (or `ENV KEY value`) instructions, capturing key and value.
File Extension
File & PathCaptures the file extension from a filename.