Skip to content

Query Syntax

Code Search supports a rich query language for searching code. This guide covers everything from basic searches to advanced query techniques.

By default, search queries match as exact substrings. Type what you’re looking for and it will match literally.

func main()

Matches the exact string func main() in your code.

fmt.Println

Matches the exact string fmt.Println.

When you use query operators (like repo:, lang:, file:, etc.), the query is parsed using Zoekt’s query language. In this mode, search terms are treated as regular expressions using Go’s regexp syntax.

lang:go func\s+main\(

Uses regex to match func followed by whitespace and main( in Go files.

A query with operators consists of one or more expressions separated by spaces. Each expression is treated as a pattern to match.

QueryMeaning
fooMatch the exact substring foo
lang:go foo barMatch both /foo/ AND /bar/ in Go files (regex mode)
"foo bar"Match the literal string foo bar (space included)

By default, multiple expressions are combined with AND logic. A file must contain matches for all expressions to appear in results.

repo:myorg foo bar baz

Returns files containing ALL of: /foo/, /bar/, and /baz/ in the myorg repository.

Use or to combine expressions disjunctively:

repo:myorg foo or bar

Returns files containing /foo/ OR /bar/ (or both).

Group expressions to create complex logic:

repo:myorg foo (bar or baz)

Returns files with /foo/ AND (either /bar/ OR /baz/).

Groupings can be nested:

repo:myorg (foo or bar) (baz or qux)

Prefix an expression with - to exclude matches:

foo -bar

Returns files with /foo/ that do NOT contain /bar/.

Negation works with groups:

foo -(bar or baz)

Excludes files with either /bar/ or /baz/.

foo -(bar baz)

Excludes files with BOTH /bar/ and /baz/.

Field prefixes restrict where a pattern matches. Without a field prefix, patterns match both file names and content.

FieldDescriptionExample
file:Match file names onlyfile:README
content:Match file contents onlycontent:TODO
repo:Filter by repository namerepo:linux
branch:Filter by branch namebranch:main
lang:Filter by programming languagelang:go
sym:Match symbol definitions (ctags)sym:main
file:README

Matches files with “README” in their name.

content:TODO

Matches “TODO” only in file contents (not file names).

repo:myorg/api lang:go func.*Handler

Search for func.*Handler in Go files within the myorg/api repository.

-file:test assert

Match /assert/ but exclude files with “test” in their name.

The case: modifier controls case matching:

ValueBehavior
case:autoCase-sensitive if pattern has uppercase (default)
case:yesAlways case-sensitive
case:noAlways case-insensitive
FOO case:yes

Matches only FOO, not foo or Foo.

TEST case:no

Matches TEST, test, Test, etc.

Control what kind of results are returned:

ValueDescription
type:filematchFile content matches (default)
type:filenameOnly matching filenames
type:repoOnly repository names
type:repo config

Returns repository names matching “config” instead of file matches.

The regex: operator treats the following pattern as a regular expression, even without other query operators:

regex:func\s+main\(

Matches func followed by whitespace and main( using regex.

Field values can be plain text, quoted strings, or regex:

repo:myproject
lang:typescript

Use double quotes for values with spaces or special characters:

file:"my file.txt"
content:"foo bar"
repo:"my org/my project"

Use forward slashes for regex patterns:

content:/func\s+\w+\(/
file:/.*\.test\.ts$/
repo:/github\.com\/myorg\/.*/

Escape special characters with backslash:

content:"foo\"bar"
file:my\ file.txt

The lang: field filters by programming language as detected by go-enry (based on linguist):

LanguageAlso matches
lang:goGo
lang:pythonPython
lang:javascriptJavaScript
lang:typescriptTypeScript
lang:javaJava
lang:rustRust
lang:cC
lang:cpp or lang:c++C++
lang:go func\s+\w+\(
lang:go ^import\s
regex:(TODO|FIXME|HACK|XXX):
file:(config|settings)\.(json|yaml|yml|toml)$
myfunction -file:test -file:spec -file:mock
repo:myorg/myrepo lang:go error handling

Search for HTTP handlers in Go:

lang:go func.*Handler repo:api

Find potential SQL injection:

lang:go (exec|query).*\+.*\$

Find unused exports:

sym:deprecated -file:test

Find package imports:

lang:go "github.com/pkg/errors"

Find error handling in Go, excluding tests:

lang:go (err != nil) -file:_test\.go

Search multiple repos for a pattern:

(repo:frontend or repo:backend) auth

Find README files:

type:filename README

Case-sensitive class name search:

lang:java class MyService case:yes

Find files modified in feature branches:

branch:/feature-.*/ config
OperatorExampleDescription
(space)foo barAND (both required)
orfoo or barOR (either match)
--fooNOT (exclude)
()(a or b) cGrouping
"""foo bar"Literal string
///foo.*/Regex pattern
FieldValuesDescription
file:text/regexFile name filter
content:text/regexContent only filter
repo:text/regexRepository filter
branch:text/regexBranch filter
lang:language nameLanguage filter
sym:text/regexSymbol definitions
case:yes/no/autoCase sensitivity
type:filematch/filename/repoResult type
regex:patternInline regex mode
  1. Start Simple: Begin with plain text and add filters as needed
  2. Use Quotes: When searching for phrases with spaces
  3. Add Filters: Use repo: or lang: to narrow results quickly
  4. Exclude Noise: Use -file:test to skip test files
  5. Use Regex Mode: Add regex: prefix for complex pattern matching
  6. Check Case: Use case:auto (default) for smart matching