Reputation: 6898
I am at a loss what is making this simple command not return any matches. I get zero results in all variations below:
find . -type d -regex '.+ [0-9]{4}' -print | wc -c;
find * -type d -regex '.+[0-9]{4}' -print | wc -c;
find * -type d -regex '.+[0-9]' -print | wc -c;
find . -type d -regex '[0-9]' -print | wc -c;
If I use '.+' regex then I get all results as expected. Directories are name in this pattern: [1 or more words] [4 digits]. I want to match any directory ending in a year and print it. What am I missing here?
Upvotes: 0
Views: 65
Reputation: 18611
Use -regextype 'posix-extended'
with your regex:
find . -type d -regextype 'posix-extended' -regex '.*[0-9]{4}' -print | wc -c
This expression will returns all directories ending in four digits.
Upvotes: 0
Reputation: 785246
You need to use -regextype
option with an extended regex type e.g.:
find . -type d -regextype egrep -regex '.+-[0-9]{4}$
Note that default value of -regextype
is emacs
Upvotes: 1