Is there a way to use extended regular expressions(ERE) in a .gitignore file? For example I want to use the + repetition character in a .gitignore file. Is there a way to do that?
- 2,834
- 15
- 68
- 140
2 Answers
As illustrated here and detailed in "this question", the function fnmatch() is involved to interpret glob patterns, which means regular expressions are not supported.
This is what gitignore man page mentions:
Otherwise,
git treats the pattern as a shell glob suitable for consumption by fnmatch(3)with theFNM_PATHNAMEflag: wildcards in the pattern will not match a/in the pathname.
For example, "Documentation/*.html" matches "Documentation/git.html" but not "Documentation/ppc/ppc.html" or "tools/perf/Documentation/perf.html".
You can see some correspondence between glob patterns and regular expressions in those questions.
The .gitignore (and other) files use filename globs, not regular expressions.
I very much doubt you can convince the git hackers to change that: Just too ingrained by now, and globs are much more familiar as filename matchers.
- 11,412
- 8
- 32
- 52
-
13That's a pity. Such a handy feature could it be. – Artur Barseghyan Apr 17 '14 at 08:02
-
3@ArturBarseghyan, consider Mercurial, it has that neat feature and many other cool features too. – toriningen Apr 04 '15 at 20:46
-
@modchan: I know it exists in Mercurial and I use it a lot. Thanks for the comment anyway. – Artur Barseghyan Apr 07 '15 at 14:29
-
2Has someone tried submitting a patch? Who knows, perhaps the git hackers would also find this useful. – Alexander Jan 03 '18 at 10:18