1

Problem

I tried to implement a negative lookahead when searching a file with locate like this:

locate --regex "apple(?!t)"

However I'm getting the following error, because there seems to be some substitution going on:

locate: invalid regexp `apple(?touch latex_preamble.tex)': Invalid preceding regular expression

How can I make this work? I tried apple(?!t) and apple(?!t) as well.

NOTE: I'm aware I can do this with:

locate apple | grep -v applet

but I would like to know how I can get the regular expression to work.

1 Answer 1

1

There are several implementations of locate, and the ones I'm aware of want either POSIX extended regexps, or POSIX basic regexps. Neither support lookaheads.

1
  • Thank you! In that case I'll have to resort to grep. Commented Jul 17, 2015 at 16:23

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.