user1413300
user1413300

Reputation: 71

Regular expression error

I have a regular expression that seams to work in Javascript, but doesn't work with the Linux find command. The purpose is to gather a list of files that have been updated in the last 90 days, excluding particular directories (for example, assume I want to include the directory /data/safe/23/test, but not /data/safe/23/skip1). Here is the regex:

^/data/safe/\d{1,4}/(?:(?!skip1|skip2).*)

And here is the find command (notice I'm using posix-extended; that may be the problem):

find /data/safe -regextype posix-extended -regex '^/data/safe/\d{1,4}/(?:(?!skip1|skip2).*)' -mtime -90

And finally this is the error that is generated:

find: Invalid preceding regular expression

Any help is greatly appreciated!

Upvotes: 3

Views: 2026

Answers (2)

Raymond Tau
Raymond Tau

Reputation: 3469

I think that posix-extended does not supports "?:" and "?!".

Anyway, with find, it would be easier to use something like:

find /data/safe -regextype posix-extended -regex '^/data/safe/[0-9]{1,4}/.*' ! -regex '^/data/safe/[0-9]{1,4}/(skip1|skip2).*' -mtime -90

Upvotes: 2

Markus Tankle
Markus Tankle

Reputation: 11

You're doing it wrong. You need to replace the curly brackets with asterisks. Also you should be piping that whole thing through the tar or touch commands.

Upvotes: 1

Related Questions