Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a bunch js and css files in a directory. Some of them have been given a name based on an md5() of their content (looks like f10521a21bb013cb81e0909809818ad6.js). I'd like to match these files using find. Why does this return 0 results?

find -regex "^[A-f0-9]{32}\.(?:js|css)$"
share|improve this question
    
Instead of A-f, I guess you either mean a-f, or A-Fa-f. –  user unknown May 4 '12 at 19:50

1 Answer 1

up vote 7 down vote accepted
  • The regular expression is matched against the path, not just the file name, so do not anchor it to the beginning of string.
  • The default emacs type regular expression seems to not like intervals. Choose another.
  • Neither the other regular expression types seem to like the non capturing groups.

These work, supposing you are using GNU find:

find . -regextype posix-awk -regex ".*/[a-f0-9]{32}\.(js|css)$"

find . -regextype posix-basic -regex ".*/[a-f0-9]\{32\}\.\(js\|css\)$"

find . -regextype posix-egrep -regex ".*/[a-f0-9]{32}\.(js|css)$"

find . -regextype posix-extended -regex "/[a-f0-9]{32}\.(js|css)$"
share|improve this answer
    
works perfectly. thank you –  sean9999 May 4 '12 at 17:31
    
@sean If it works for you, please consider accepting the answer. –  Eugene S May 4 '12 at 20:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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