Go (RE2)

Hidden File (Dotfile) in GO

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

Try it in the GO tester →

Pattern

regexGO
^\.[^.\s/\\][^/\\]*$

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.

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)