0

Putting

syntax:regexp
*.foo.[a-z]{1,4}

in .gitignore does not work. I remember seeing

syntax:glob

and

syntax:regexp

some time ago in some .gitignore files, but I couldn't file such syntax in Git manual. Is there a way to use regular regex in .gitignore?

qazwsx
  • 25,536
  • 30
  • 72
  • 106

2 Answers2

3

Without using any regex syntax that might or might not be supported (I don't see any evidence for it either), you could get the same behavior with four rules:

*.foo.[a-z]
*.foo.[a-z][a-z]
*.foo.[a-z][a-z][a-z]
*.foo.[a-z][a-z][a-z][a-z]

If you wanted to compromise slightly, you could use *.foo.?* (anything ending in foo, a dot, and at least one more character), or *.foo.[a-z]* (anything ending in foo and then an extension that starts off alphabetic).

hobbs
  • 223,387
  • 19
  • 210
  • 288
2

You are confusing .hgignore with .gitignore.

There is no such thing as a "normal file name extension"; what you can do to start off with is to add the following:

**/foo.*

**/ will match foo.* in all directories.

.gitignore uses the shell glob syntax:

Git treats the pattern as a shell glob suitable for consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in the pattern will not match a / in the pathname.

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284