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! :-(
To locate a string within a file, use the grep tool. The grep tool searches the named input files for lines containing a match to the given pattern. By default, grep prints the matching lines.
The git grep version will only search in files tracked by git, whereas the grep version will search everything in the directory.
`git grep` command is used to search in the checkout branch and local files. But if the user is searching the content in one branch, but the content is stored in another branch of the repository, then he/she will not get the searching output.
A word boundary is a zero-width test between two characters. To pass the test, there must be a word character on one side, and a non-word character on the other side. It does not matter which side each character appears on, but there must be one of each.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With