How do I escape characters in GitHub code search?

SearchGithubElasticsearch

Search Problem Overview


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.

Search Solutions


Solution 1 - Search

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.

Solution 2 - Search

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.

Solution 3 - Search

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

Solution 4 - Search

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEli RoseView Question on Stackoverflow
Solution 1 - SearchChintanShah25View Answer on Stackoverflow
Solution 2 - SearchRan Ever-HadaniView Answer on Stackoverflow
Solution 3 - SearchVijay NirmalView Answer on Stackoverflow
Solution 4 - SearchfarukgView Answer on Stackoverflow