Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I generally use the following command to match patterns

find . -maxdepth 1 -regextype posix-egrep -regex '.*/{pattern}'

However when I attempt to use a lookahead for example, no results are returned although it works when I use sites such as gSkinner

find . -maxdepth 1 -regextype posix-egrep -regex '.*/Linux(?=W).*'

What am I doing wrong?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

find (both the GNU and BSD variants) do not support lookahead/lookbehind. GNU grep only supports the POSIX basic and extended regular expression variants as well as a couple of others.

Lookahead and lookbehind are Perl-style regular expression elements, so you'd have to use Perl directly, or GNU grep with the -P option, which then interprets Perl regex.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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