'git grep' and word boundaries on Mac OS X and BSD

I run git grep "\<blah\>" regularly on my linux development server, but I just discovered that I am not able to use \< and \> on Mac (Mac OS X 10.6.8) (not able to use = it does not find anything). Is the regular expressions syntax different in Mac?

I tried using git grep -E "\<blah\>" but to no avail! 🙁

  • Git Install as User?
  • Git Install in Home Directory as User: Errors?
  • lesskey config does not get used by less pager when used with git on OSX
  • Git post-checkout hook from in repo
  • Is there a 'git sed' or equivalent?
  • How to check out a branch in Bitbucket
  • git rebase onto remote updates
  • In Git, list names of branches with unpushed commits
  • Update of blog site via cron does not work
  • 3 Solutions collect form web for “'git grep' and word boundaries on Mac OS X and BSD”

    I guess it’s caused by the BSD vs Linux grep library.

    See if the -w (match pattern only at word boundary) option to git grep does it for you:

    $ git grep -w blah
    

    You can compile git with PCRE support and use git grep -P "\bblah\b" for word boundaries.

    Here’s a guide on how to compile git using OSX Homebrew:
    http://realultimateprogramming.blogspot.com/2012/01/how-to-enable-git-grep-p-on-os-x-using.html

    After struggling with this, too, I found this very helpful post on a BSD mailing list. So here’s the (albeit rather ugly) solution:

    git grep "[[:<:]]blah[[:>:]]"
    

    The -w flag of git-grep also works but sometimes you want to only match the beginning or end of a word.

    Update: This has changed in OS X 10.9 “Mavericks”. Now you can use \<, \>, and \b. [[:<:]] and [[:>:]] are no longer supported.

    Git Baby is a git and github fan, let's start git clone.