You can search for specific files or code snippets by using the search box located at the top of the Google Cloud Console.
All searches use RE2 regular expressions by default. If you don't want to use regular expressions, enclose your search in double quotation marks ( " ). For example:
foo() # Parentheses are treated as part of a regular expression. Matches 'food'. "foo()" # Treats the parentheses as literals. Doesn't match 'food'.
Setting search scope
The Scope drop-down list to the left of the search box lets you restrict your search scope to one of the following, depending on your location in the source repository interface:
- Everything: Searches all repositories where you have access.
- This Project: Searches all repositories in the current project.
- The Repository: Searches the current repository.
- This Directory: Searches the current directory.
Searching for files
You can search for a file in several ways. For example, you can use the
filter to search for a file by using its path. For example:
The following filters return the same results as the
You can also search for a file name by typing its name and extension. For example:
Searching file contents
You can restrict your search to the contents of a file by using the
filter. For example, the following query looks for the term
main in the
contents of all Java files. It does not search for instances where a path
contains the term
Searching by language
To restrict your search results to a specific language, use the
lang filter. For example, the following search restricts the search results to
the Java language:
You can also use the
file filter, as shown in the following example:
Remember that searches use regular expressions by default. As a result, the following search doesn't work:
Instead, try the following searches:
Enabling case-sensitive searches
You can make your search case-sensitive by using the
case filter. For example,
the following search returns only results that match the term
It excludes results where the case doesn't match, such as
Searching for classes
To search for a specific class, use the
class keyword. For example, the
following search returns all classes with the term
Searching for functions
func filters to search for a specific function. For
example, the following search returns all functions with the term
To exclude a term from search results, prepend the
- character to the term
you want to exclude. For example, the following search returns all functions
with the term
main, but excludes matches found in C++ files.
By default, searches use
RE2 regular expressions.
To escape characters so they aren't treated as part of a regular expression,
\ character. For example, the following example searches for the term
Searching for literals
Enclose your search terms in double quotation marks (
") to perform a literal
search. For example, the following example searches for the term
Searching for symbols
To search for a specific symbol, use the
symbol keyword. For example, the
following search returns all immutable classes and functions.
Using the AND operator
You can search for multiple terms by using the
AND operator. This operator
returns results only when the terms on both sides of the operator are true.
For example, the following search returns Python files that contain the term
server AND lang:python
A search for multiple terms uses
AND implicitly. For example, you could write
the preceding example as follows:
Using the OR operator
OR operator returns a result if it matches an expression on either side
of the keyword. For example, the following search returns files that contain the
hello or the term
hello OR world
Grouping search terms
You can group multiple search terms together using parentheses (
(hello OR world) AND lang:java
You can also nest multiple groups. For example:
((Strings OR StringBuilder) AND lang:java) OR (std AND lang:cpp)
Previewing search results
A search query might have multiple results in the same file. For example:
This search looks for Java files that have a
foo function. These files might
contain more than one reference to this function, however. In these situations,
the search result for that file contains a View all matches in this file
link. Click this link to open a preview pane that displays the contents of this
Use the preview pane to quickly preview multiple results at once while still keeping the rest of your search results in view.
The following tables contain the search filters and operators discussed in the preceding section.
The following table lists the filters you can use when searching code.
|case:yes||Make the search case sensitive. By default, searches are not case
If you are grouping multiple search terms, this filter is inherited by all child groups.
|class:||Search for a class name.||
|content:||Search only for file names and file contents.||
|Search for a file by its path.||
|function:||func:||Search for a function name.||
|lang:||language:||Search for results by using a specific language.||
The following table lists the operators you can use when searching code.
|AND||Logical `AND` operator. For more information, see Using the AND operator.|
|OR||Logical `OR` operator. For more information, see Using the OR operator.|
|([SEARCH_EXPRESSION])||Groups multiple terms together. For more information, see Grouping search terms.|
|-||Excludes the term from search results.|
|\||Escapes special characters such as
|"[SEARCH_EXPRESSION]"||Perform a search without interpreting the search query as a regular expression.|