0

Assume I have the following two files:

fileA.pdf
pp_1234_fileB.pdf

If I am to run the following in PowerShell, the file, fileA.pdf is returned.

get-childitem -file -recurse | where-object {$_.Name -match "^(?!pp_[0-9]{4}_).*\.pdf"}

but if I try to do the following similar searches in WSL (Ubuntu), I do not get any files returned:

find -regextype egrep -regex '.*/(?!pp_[0-9]{4}_).*\.pdf'
find -regextype egrep -regex '.*/(?!.*pp_[0-9]{4}_).*\.pdf'

I am an extreme novice with respect to regex on Linux so I'm sure I am missing some sort of syntax mistake. Can you please point out why I'm failing and what a working solution would look like.

Thanks!

Brian
  • 1,085

1 Answers1

0

Find does not support negative look behind. Instead, the following solves the above problem:

find ./ -iname "*.pdf" | grep -Po '.*/(?!.*pp_[0-9]{4}_).*\.pdf'

From what I understand (which is limited), the -P specifies to use Perl-regex and o specifies that it is only matching. With Perl, negative-lookbehind works.

Brian
  • 1,085