Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extended regular expressions (ERE) for .gitignore

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?

like image 735
Jacob Krieg Avatar asked Mar 28 '13 01:03

Jacob Krieg


People also ask

Does Gitignore support regex?

No, gitignore doesn't support regex es, it only supports unix fnmatch style patterns.

What is extended regular expression?

An extended regular expression specifies a set of strings to be matched. The expression contains both text characters and operator characters. Text characters match the corresponding characters in the strings being compared. Operator characters specify repetitions, choices, and other features.


1 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 the FNM_PATHNAME flag: 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.

like image 140
VonC Avatar answered Sep 28 '22 04:09

VonC