Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression error

Tags:

regex

find

posix

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!

like image 657
user1413300 Avatar asked May 02 '26 11:05

user1413300


2 Answers

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
like image 143
Raymond Tau Avatar answered May 05 '26 09:05

Raymond Tau


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.

like image 32
Markus Tankle Avatar answered May 05 '26 09:05

Markus Tankle