首页 / 民族发展 / 正文
Understanding GitHub Code Search syntax

Time:2025年10月01日 Read:31 评论:0 作者:mlgyp_com

  The search syntax in this article only applies to searching code with GitHub code search. Note that the syntax and qualifiers for searching for non-code content, such as issues, users, and discussions, is not the same as the syntax for code search. For more information on non-code search, see About searching on GitHub and Searching on GitHub.   Search queries consist of search terms, comprising text you want to search for, and qualifiers, which narrow down the search.   A bare term with no qualifiers will match either the content of a file or the file's path.   For example, the following query:   The above query will match the file , even if it doesn't contain the term . It will also match a file called if it contains the term .   You can enter multiple terms separated by whitespace to search for documents that satisfy both terms.   For example, the following query:   The search results would include all documents containing both the terms and , in any order. As examples, it would match a file containing , a file with the phrase , and even a file named that contains the term .   Searching for multiple terms separated by whitespace is the equivalent to the search . Other boolean operations, such as , are also supported. For more information about boolean operations, see Using boolean operations.   Code search also supports searching for an exact string, including whitespace. For more information, see Query for an exact match.   You can narrow your code search with specialized qualifiers, such as , and . For more information on the qualifiers you can use in code search, see Using qualifiers.   You can also use regular expressions in your searches by surrounding the expression in slashes. For more information on using regular expressions, see Using regular expressions.   To search for an exact string, including whitespace, you can surround the string in quotes. For example:   You can also use quoted strings in qualifiers, for example:   To search for code containing a quotation mark, you can escape the quotation mark using a backslash. For example, to find the exact string , you can search:   To search for code containing a backslash, , use a double backslash, .   The two escape sequences and can be used outside of quotes as well. No other escape sequences are recognized, though. A backslash that isn't followed by either or is included in the search, unchanged.   Additional escape sequences, such as to match a newline character, are supported in regular expressions. See Using regular expressions.   Code search supports boolean expressions. You can use the operators , , and to combine search terms.   By default, adjacent terms separated by whitespace are equivalent to using the operator. For example, the search query is the same as , meaning that the search results will include all documents containing both the terms and , in any order.   To search for documents containing either one term or the other, you can use the operator. For example, the following query will match documents containing either or :   To exclude files from your search results, you can use the operator. For example, to exclude files in the directory, you can search:   You can use parentheses to express more complicated boolean expressions. For example:   You can use specialized keywords to qualify your search.   Repository qualifier   Organization and user qualifiers   Language qualifier   Path qualifier   Symbol qualifier   Content qualifier   Is qualifier   To search within a repository, use the qualifier. You must provide the full repository name, including the owner. For example:   To search within a set of repositories, you can combine multiple qualifiers with the boolean operator . For example:   To search for files within an organization, use the qualifier. For example:   To search for files within a personal account, use the qualifier. For example:   To narrow down to a specific languages, use the qualifier. For example:   For a complete list of supported language names, see languages.yaml in github-linguist/linguist. If your preferred language is not on the list, you can open a pull request to add it.   To search within file paths, use the qualifier. This will match files containing the term anywhere in their file path. For example, to find files containing the term in their path, use:   The above query will match both and since they both contain somewhere in their path.   To match only a specific filename (and not part of the path), you could use a regular expression:   Note that the in the filename is escaped, since has special meaning for regular expressions. For more information about using regular expressions, see Using regular expressions.   You can also use some limited glob expressions in the qualifier.   For example, to search for files with the extension , you can use:   To search for JavaScript files within a `src` directory, you could use:   By default, glob expressions are not anchored to the start of the path, so the above expression would still match a path like . But if you prefix the expression with , it will anchor to the start. For example:   Note that doesn't match the character, so for the above example, all results will be direct descendants of the directory. To match within subdirectories, so that results include deeply nested files such as , you can use . For example:   You can also use the global character. For example, to match the path or , you can use:   To search for a filename which contains a special character like `*` or `?`, just use a quoted string:   Glob expressions are disabled for quoted strings, so the above query will only match paths containing the literal string .   You can search for symbol definitions in code, such as function or class definitions, using the qualifier. Symbol search is based on parsing your code using the open source Tree-sitter parser ecosystem, so no extra setup or build tool integration is required.   For example, to search for a symbol called :   In some languages, you can search for symbols using a prefix (e.g. a prefix of their class name). For example, for a method on a struct , you could search if you are using Go, or in Rust.   You can also use regular expressions with the symbol qualifier. For example, the following query would find conversions people have implemented in Rust for the type:   Note that this qualifier only searches for definitions and not references, and not all symbol types or languages are fully supported yet. Symbol extraction is supported for the following languages:   Bash   C   C#   C++   CodeQL   Elixir   Go   JSX   Java   JavaScript   Lua   PHP   Protocol Buffers   Python   R   Ruby   Rust   Scala   Starlark   Swift   Typescript   We are working on adding support for more languages. If you would like to help contribute to this effort, you can add support for your language in the open source Tree-sitter parser ecosystem, upon which symbol search is based.   By default, bare terms search both paths and file content. To restrict a search to strictly match the content of a file and not file paths, use the qualifier. For example:   This query would only match files containing the term , rather than matching files named .   To filter based on repository properties, you can use the qualifier. supports the following values:   : restricts the search to archived repositories.   : restricts the search to forked repositories.   : restricts the search to content detected as vendored.   : restricts the search to content detected as generated.   For example:   Note that the qualifier can be inverted with the operator. To search for non-archived repositories, you can search:   To exclude forks from your results, you can search:   Code search supports regular expressions to search for patterns in your code. You can use regular expressions in bare search terms as well as within many qualifiers, by surrounding the regex in slashes.   For example, to search for the regular expression , you would use:   Note that you'll have to escape any forward slashes within the regular expression. For example, to search for files within the directory, you would use:   Inside a regular expression, stands for a newline character, stands for a tab, and can be used to escape any Unicode character. This means you can use regular expressions to search for exact strings that contain characters that you can't type into the search bar.   Most common regular expressions features work in code search. However, "look-around" assertions are not supported.   All parts of a search, such as search terms, exact strings, regular expressions, qualifiers, parentheses, and the boolean keywords , , and , must be separated from one another with spaces. The one exception is that items inside parentheses, , don't need to be separated from the parentheses.   If your search contains multiple components that aren't separated by spaces, or other text that does not follow the rules listed above, code search will try to guess what you mean. It often falls back on treating that component of your query as the exact text to search for. For example, the following query:   Code search will give up on interpreting the parentheses and quotes as special characters and will instead search for files containing that exact code.   If code search guesses wrong, you can always get the search you wanted by using quotes and spaces to make the meaning clear.   By default, code search is case-insensitive, and results will include both uppercase and lowercase results. You can do case-sensitive searches by using a regular expression with case insensitivity turned off. For example, to search for the string "True", you would use:
Understanding GitHub Code Search syntax
(图片来源网络,侵删)
标签: Understanding  GitHub  Code  Search  syntax 
关于我们
民贸生活服务网为您整理的分类信息及实用建议,涵盖生活各方面需求:【房产资讯】二手房市场:近期政策利好,首付比例下调至15%,建议关注地铁沿线学区房租房指南:9月开学季租金普遍上涨5-10%,建议提前1个月锁定房源新房动态:智能家居成标配,精装房交付标准升级【美食探店】• 必吃榜单:秋季限定蟹黄汤包上市(推荐老字号王记)• 网红打卡:新开业的星空主题餐厅,人均150元需提前3天预约• 省钱攻略:每周三半价日活动覆盖30+连锁餐厅【社区活动】✓ 9月8日社区文化节(免费参与包粽子比赛)✓ 每周六上午跳蚤市场(二手家具5折起)✓ 中秋晚会节目招募(报名截止9月15日)【婚恋服务】❤ 实名认证相亲会:9月14日七夕专场(需提供学历/房产证明)❤ 线上匹配:推荐知心红娘小程序,AI算法匹配度达85%【智能生活】• 家电换新:以旧换新补贴最高2000元(限9月30日前)• 黑科技:可语音控制的智能窗帘套装(安装仅需2小时)【金融理财】💰 大额存单利率:3年期2.85%(较上月上涨0.1%)💰 黄金投资:金价回调至480元/克,适合分批建仓【旅游推荐】✈ 错峰游:9月三亚机票价格回落40%🚗 周边游:新开通的环湖绿道适合骑行(租车点:社区服务中心)【生活服务】• 家政保洁:开学季大扫除预约已排至9月20日• 维修服务:空调清洗特惠99元(需提前3天预约)【二手市场】📌 急转:9成新婴儿床(原价1800元,现价600元)📌 求购:求购二手钢琴(预算3000元内)实用建议:房产交易前务必查验五证原件相亲时建议选择公共场所首次见面旅游旺季建议购买取消险(可退80%费用)需要更详细的某类信息,欢迎随时告知!
扫码关注
Copyright ©2004-2025 Comsenz Inc.Powered
蜀ICP备2025157516号-4