Bash on GNU:

I am using a collection of find commands, most of which employ -regex to do their matching. Each time I try a different feature in my regex I have to cycle through the values for -regextype until one works. My particular need in this case is for one that supports negative lookbehind. It's hard to validate the (zero) results of my tests on this feature so I would like to simply refer to a list rather than repeating increasing series of tests.

I have found many references to Javascript and other platforms not supporting negative lookbehind, but I can't seem to find a central location for those which do.

It would be nice to see a chart somewhere listing many of the popular regex styles and the features they do and do not support, but I couldn't find that either.

  • 1
    I knew just a perl invocation of regex to support lookbehind (negative included). I have met it in grep with -P option but not sure for find and other command. Format of expressions you can find in man pcre. But I am sure that for more cases there are many ways to omit pcre usage in find or somewhere else. – Costas Feb 5 '15 at 19:27
  • 3
    more information on the "regextype" types at gnu.org/software/gnulib/manual/html_node/… – glenn jackman Feb 5 '15 at 21:05
  • Wikipedia! Also, Why does my regular expression work in X but not in Y? for an overview. – Gilles Feb 6 '15 at 22:20
  • @Gilles That is a good chart, but does it distinguish between the -regextype options for find? The man page lists "emacs (this is the default), posix-awk, posix-basic, posix-egrep and posix-extended". – WAF Feb 8 '15 at 18:24

If you want a find whose -regex supports look-around operators à la perl, you can use ast-open's find:

$ find /etc -regex '.*(?<!g)shadow'

-regextype is specific to the GNU implementation of find and none of the regex types it supports have look-around operators AFAIK.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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