cdietschrun
cdietschrun

Reputation: 1683

Regex to select all .c files except ones with a certain prefix

I have what should be a real simple regex question. I'm making a makefile and need one target to compile all the source in my directory except one or two files that have a named prefix of ttem_endian_port. What regex can I use to make this as simple as possible?

I was thinking something like [^ttem_endian_port*]*.c but that doesn't seem to work.

Upvotes: 13

Views: 8944

Answers (3)

Alba Mendez
Alba Mendez

Reputation: 4635

Regexp were not made to do a negative search. If you really want to use regexp, you can make a lookahead (not all the engines support it):

^(?!ttem_endian_port).*\.c$

Also, don't forget to escape the dot. Look at this question for more information.

Upvotes: 2

eriktous
eriktous

Reputation: 6659

Do you really need a regex? make's built-in functions can do this as well.

ALL_SRCS := $(wildcard *.c)
SRCS     := $(filter-out ttem_endian_port%.c, $(ALL_SRCS))

Upvotes: 17

Elad
Elad

Reputation: 3130

^[^(ttem_endian_port)]*.c
  • The first ^ means 'beginning of string'.
  • Then, you need to parenthesize ttem_endian_port to make the regexp engine understand that you want to negate the whole term with your ^

Upvotes: 2

Related Questions