Some people on this list might find this useful.
http://takluyver.github.io/posts/astsearch-code-searching-that-knows-about-code.html
We often grep the codebase to do refactorings, or fix some API, or
whatever. This uses Python's ast to search, meaning it will filter out
false positive, and should also work with things that span multiple
lines (and you don't have to worry about whitespace).
As an example, to find all instances of .args in code (as opposed to
strings and comments), you could do
astsearch ?.args sympy/
Aaron Meurer