3

I'm using the find command in Mac OS X 10.9, I tried commands like this:

$ touch "a gre a"
$ find -E . -iregex ".*\bgre\b.*"

It looks that the find will not return this file named a gre a.. Does anyone have ideas about this? Thanks!

ruakh
  • 175,680
  • 26
  • 273
  • 307
Hanfei Sun
  • 45,281
  • 39
  • 129
  • 237

1 Answers1

6

find command's regex engine (ERE) doesn't support \b for word boundaries.

On OSX following will work for word boundaries:

find -E . -iregex ".*[[:<:]]gre[[:>:]].*"
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • You mean extended (modern) regular expressions doesn't include `\b` as shorthand, or `\b` is missing only in `find`'s ERE? Do you know how I can know whether a shorthand exist in a command's regex function.. Thanks very much! – Hanfei Sun Nov 13 '13 at 07:53
  • 1
    I believe on OSX tools `\b` isn't supported in other tools like awk, sed also. I usually find online sited to looks for documentation on ERE since man paged doesn't cover it. – anubhava Nov 13 '13 at 07:57
  • On other systems `\<` and `\>` are supported as word boundaries but OSX (BSD) has this weird syntax `[[:<:]]` and `[[:>:]]` – anubhava Nov 13 '13 at 08:03