Hidden File (Dotfile) in PY
Matches Unix-style hidden files (dotfiles) like .gitignore or .env.
Try it in the PY tester →Pattern
regexPY
^\.[^.\s/\\][^/\\]*$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+.
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
—