12

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.

cdietschrun
  • 1,623
  • 6
  • 23
  • 39

3 Answers3

16

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))
eriktous
  • 6,569
  • 2
  • 25
  • 35
2
^[^(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 ^
Elad
  • 3,145
  • 2
  • 20
  • 17
2

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.

Community
  • 1
  • 1
Alba Mendez
  • 4,432
  • 1
  • 39
  • 55