Python (re)

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

.gitignore

Matches

  • .gitignore

Input

.env.local

Matches

  • .env.local

Input

..

No match

Same pattern, other engines

← Back to Hidden File (Dotfile) overview (all engines)