Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I've got a set of files in a directory, all of the format test[0-9][0-9].txt. If I run

find . -regex ".*/(test)[0-9][0-9]\.txt"

then all the files are shown, but if I run

find . -regex ".*/(test)[0-9]{2}\.txt"

then none are shown. What am I doing wrong?!

I've had a search through previous similar questions to this, but can't find a particularly relevant answer

share|improve this question

marked as duplicate by don_crissti, slm Nov 23 '15 at 16:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
The first example uses normal regexp syntax, where the second uses extended syntax. Your version of find obviously expects the former by default. You don't say what system you're on - your find might have a switch to turn on extended regexp parsing. On FreeBSD, for example, it's -E – D_Bye Nov 23 '15 at 12:27
    
@D_Bye ah, that's a good point. CentOS6. I've tried -regextype posix-extended and that doesn't work either – ChrisW Nov 23 '15 at 12:33
up vote 2 down vote accepted

If you are using GNU find, this should work for you

 find . -regextype sed -regex "./test[0-9]\{2\}.txt"

Explanation

  • -regextype sed - use basic posix regular expression (just because thats what Im familiar with)
  • ./ - necessary because find considers all file paths on a relative search to begin with this pattern
  • [0-9]\{2\} - 2 instances of the [0-9] digit character class with the quantifier \{...\} brackets escaped - per basic posix regular expressions
share|improve this answer

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