How do I escape characters in GitHub code search?

落爺英雄遲暮 提交于 2019-12-20 15:38:11

问题


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.


回答1:


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.




回答2:


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

  • clone your company's github source website
  • do locally a git grep, which supports basic regexp or extended POSIX regexp (git grep -E)
  • or a pickaxe search (git log --all -S...
  • or git rev-list --all|grep xxx which also allows for regexp

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




回答3:


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.



来源:https://stackoverflow.com/questions/34242460/how-do-i-escape-characters-in-github-code-search

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!