161

I'm trying to use GitHub's code search to search for some lines of code containing characters like =, +, etc.

I understand from https://help.github.com/articles/searching-code/#considerations-for-code-search that these characters are wildcards and have to be escaped, otherwise they will be ignored.

Here's an example: "if \(done is True\)", and another: "if (done is True)".

Both return the same "your query contains a character that is ignored" warning on the right side of the search bar. My escaping doesn't seem to be doing anything and the results I get are with the characters ignored.

0

4 Answers 4

179

I dont think you can escape characters for github

From searching code doc:

You can't use the following wildcard characters as part of your search query: . , : ; / \ ` ' " = * ! ? # $ & + ^ | ~ < > ( ) { } [ ]. The search will simply ignore these symbols.

12
  • 23
    Right, I saw that. Is there no way to escape these characters? Meaning that if I want to search my repo for x += 2 there's no way to do that?
    – Eli Rose
    Dec 12, 2015 at 20:15
  • 1
    nope, I think github has configured elasticsearch in that way only to reduce the complexity Dec 12, 2015 at 20:49
  • 26
    What about @?
    – User
    Nov 22, 2016 at 0:57
  • 64
    ran into this; useless code search! I need to find all instances of :ok and :locked in a Ruby on Rails codebase. Github's crappy search doesn't allow this.
    – user9903
    Apr 20, 2018 at 15:31
  • 3
    @User: According to this issue, @ has been mentioned as not on the list, but no response as of yet. Sep 6, 2018 at 14:11
17

Update: Use github.dev/...., this is a official solution from github team. Just replace .com with .dev in the Url or pressing the dot ( . ) key in any repo to open in github.dev. It even works with private repo.

GitHub natively doesn't support advanced code search like using special characters or excluding or including specific folders, We can use GitHub1s for searching a code in a repo.

GitHub1s will open a repo in VSCode online (so no cloning process is required) and we can use the advanced code search provided by VSCode to search.

To open a repo in GitHub1s just replace github.com/.... with github1s.com/... to view the repo in VSCode online (In other words, add 1s before .com).

Important note: Code search in Github1s only works on public repo

enter image description here

enter image description here

9
9

You will need to do this locally. Here are some options, from https://stackoverflow.com/a/38288679/362202:

These strategies would not work for github-wide searches, which is a shame.

2
  • 31
    What if you have 1000+ repositories to search through?
    – hfm
    Nov 21, 2019 at 16:26
  • 5
    What if I wanted to share the results with someone else....as one expects from a site like github that is supposedly for collaboration?
    – Christian
    Jun 29, 2020 at 23:19
6

there is one more (some might say shameful) semi-solution/workaround: Using google...

In the search field enter site:repo-url in addition to your keywords.

I was searching for action$ in the redux-logic repo and was at least able to filter out all the other unwanted action (without the dollar-sign) results which were showing up in the github search. In Google i typed (pay attention to the quotes):

site:https://github.com/jeffbski/redux-logic "action$"

Unfortunately though, google won't list all results. That's why i wrote semi at the beginning. So you can try your luck quickly with google, if you don't find what you were looking for, fallback to checking out the git repo + search with offline-tools like vscode, intellij or cmd-line-tools as suggested by @Ran Ever-Hadani

I hope github will soon come up with a brand-new search feature, which its users can love instead of hate.

2
  • 4
    2021, bought by microsoft and those important characters for programming on "the largest and most advanced development platform in the world." as they describe themselves are ignored silently, not sure if one should laugh or cry :D
    – farukg
    Feb 23, 2021 at 23:21
  • 1
    Hopefully they'll switch to Bing soon and all these problems will be gone ;) Feb 25, 2021 at 2:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.