Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a regex I stuck in my .gitignore similar to:


It didn't work so I tested it against RegexLab.NET.

I then found the gitignore man page which led me to learn that gitignore doesn't use regexes, but rather fnmatch(3).

However, fnmatch it doesn't seem to have an equivalent of the capture groups. Is this feasible or do I need to break this into three lines?

share|improve this question
up vote 16 down vote accepted

There's no way to express this regular expression with the patterns that gitignore supports. The problem is not the lack of capture groups (in fact, you are not using capture groups as such), the problem is the lack of a | operator. You need to break this into four lines.


Note that the patterns match e.g. BigState-4foo.csv, since * matches any sequence of characters. You can't do better than this with glob patterns, unless you're willing to match only a fixed number of digits.

share|improve this answer
I ended up doing exactly what you said. Also, thanks for pointing out * does not repeat the previous expression, but is a while card. Its good enough for my needs, but I was hoping for better. – Justin Dearing Feb 17 '12 at 3:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.