Searching code

You can search for specific files or code snippets using the search box located at the top of console.

Open Cloud Source Repositories

All searches use RE2 regular expressions by default. If you do not want to use regular expressions, enclose your search in double quotes ( " ). For example:

foo() # Parentheses are treated as part of a regular expression. Matches 'food'.
"foo()" # Treats the parentheses as literals, Does not match 'food'.

Searching for files

You can search for a file in several ways. For example, you can use the file filter, to search for a file using its filepath. For example:

file:main

The following filters return the same results as the file filter:

  • filepath
  • f
  • path

You can also search for a file name by typing its name and extension. For example:

main\.java

Searching file contents

You can restrict your search to the contents of a file by using the content 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 filepath contains the term main.

lang:java content:main

Searching by language

To restrict your search results to a specific language, use the language or lang filter. For example, the following search restricts the search results to the Java language.

helloworld language:java

You can also use the file filter, as shown in the following example.

file:\.java

Remember that searches use regular expressions by default. As a result, the following search does not work:

*.java

Instead, try the following searches:

.java
lang:java

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, HelloWorld. It excludes results where the case does not match, such as helloWorld or helloworld.

case:yes HelloWorld

Searching for classes

To search for a specific class, use the class keyword. For example, the following search returns all classes with the term Main.

class:Main

Searching for functions

Use the function or func filters to search for a specific function. For example, the following search returns all functions with the term main.

function:main

Excluding terms

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.

function:main -lang:cpp

Escaping characters

By default, searches use RE2 regular expressions. To escape characters so they aren't treated as part of a regular expression, use the \ character. For example, the following example searches for the term, main.java.

main\.java

Searching for literals

Enclose your search terms in quotes (") to perform a literal search. For example, the following example searches for the term, main.java.

"main.java"

Searching for symbols

To search for a specific symbol, use the symbol keyword. For example, the following search returns all immutable classes and functions.

symbol:immutable

Using the AND operator

You can search for multiple terms 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.

server AND lang:python

A search for multiple terms uses AND implicitly. For example, you could write the preceding example as follows:

server lang:python

Using the OR operator

The 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 term hello or the term world.

hello OR world

Grouping search terms

You can group multiple search terms together using parentheses (( and )). For example:

(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:

lang:java function:foo

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 file.

Use the preview pane to quickly preview multiple results at once while still keeping the rest of your search results in view.

Search reference

Search filters

The following table lists the filters you can use when searching code.

Filter Other options Description Example
case:yes Make the search case sensitive. By default, searches are not case sensitive.

If you are grouping multiple search terms, this filter is inherited by all child groups.
case:yes Hello World
class: Search for a class name. class:MainClass
content: Search only for file names and file contents. content:hello
file: filepath:
path:
f:
Search for a file by file path. file:test.js
function: func: Search for a function name. function:print
lang: language: Search for results by using a specific language. lang:java test

Search operators

The following table lists the operators you can use when searching code.

Operator Other options Description
AND Logical `AND` operator. See Using the AND operator for more information.
OR Logical `OR` operator. See Using the AND operator for more information.
([SEARCH_EXPRESSION]) Groups multiple terms together. See Grouping search terms for more information.
- Excludes the term from search results.
\ Escapes special characters such as ., \, or (.
"[SEARCH_EXPRESSION]" Perform a search without interpreting the search query as a regular expression.
Was this page helpful? Let us know how we did:

Send feedback about...

Cloud Source Repositories