How Google Code Search Worked: Regex Matching with a Trigram Index (2012)
You can store a local search index of your code using https://github.com/google/codesearch, which uses this algorithm in the background.