matth
matth

Reputation: 2696

ignore files ending with numbers with 0-3 digits

This question must have been asked before, but I was not able to find an answer.
I want to use .gitignore to ignore all of the following files:

dsmodelext.c
dsmodelext1.c
dsmodelext2.c
dsmodelext23.c
dsmodelext107.c

Currently I put four lines in my .gitignore file:

dsmodelext.c
dsmodelext[0-9].c
dsmodelext[0-9][0-9].c
dsmodelext[0-9][0-9][0-9].c

Is there a way to express the same on a single line?

Upvotes: 6

Views: 2725

Answers (2)

Johannes
Johannes

Reputation: 6717

given the files

dsmodelext.c
dsmodelext1.c
dsmodelext2.c
dsmodelext23.c
dsmodelext2x3.c
dsmodelext107.c
dsmodelext107foo.c

The glob pattern dsmodelext*[0-9].c would match

dsmodelext1.c
dsmodelext2.c
dsmodelext23.c
dsmodelext2x3.c
dsmodelext107.c

For some of these number usecases this is a good enough approximation.

Upvotes: 2

dtech
dtech

Reputation: 14060

Gitignore takes it's syntax from fnmatch/glob, which is specified in man glob(7).

There doesn't seem to be a way to indicate a certain number of characters need to be matched, like you could with the regular expression dsmodelext[0-9]{0,3}.c

You could decide to be lenient and just defined dsmodelext*.c to be ignored.

Upvotes: 5

Related Questions