Skip to content

Query Syntax

Code Search uses the Zoekt query language for powerful code searching. This guide covers everything from basic searches to advanced query techniques.

All queries in Zoekt are parsed as regular expressions using Go’s regexp syntax. This means queries containing regex special characters must escape them to match literally.

For example:

  • foo.bar matches fooxbar (. matches any character)
  • foo\.bar or "foo.bar" matches literally foo.bar

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

QueryMeaning
fooMatch the regex /foo/
foo barMatch both /foo/ AND /bar/ in the same file
"foo bar"Match the literal string foo bar (space included)
foo\ barSame as above (escaped space)

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

foo bar baz

Returns files containing ALL of: /foo/, /bar/, and /baz/.

Use or to combine expressions disjunctively:

foo or bar

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

Group expressions to create complex logic:

foo (bar or baz)

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

Groupings can be nested:

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

FieldAliasDescriptionExample
file:f:Match file names onlyfile:README
content:c:Match file contents onlycontent:TODO
repo:r:Filter by repository namerepo:linux
branch:b:Filter by branch namebranch:main
lang:l: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.

-f:test assert

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

FieldValuesDescriptionExample
archived:yes, noFilter archived reposarchived:no
fork:yes, noFilter forked reposfork:no
public:yes, noFilter public/private repospublic:yes
archived:no fork:no readme

Search for “readme” in non-archived, non-forked repositories.

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.

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

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

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 in non-archived repos:

type:filename README archived:no

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
FieldAliasValuesDescription
file:f:text/regexFile name filter
content:c:text/regexContent only filter
repo:r:text/regexRepository filter
branch:b:text/regexBranch filter
lang:l:language nameLanguage filter
sym:-text/regexSymbol definitions
case:-yes/no/autoCase sensitivity
type:t:filematch/filename/repoResult type
archived:a:yes/noArchived repos
fork:-yes/noForked repos
public:-yes/noPublic repos
  1. Start Simple: Begin with basic patterns and add filters as needed
  2. Use Quotes: When searching for phrases or special characters
  3. Leverage Regex: For complex pattern matching
  4. Filter Early: Add repo: or lang: to narrow results quickly
  5. Exclude Noise: Use -file:test to skip test files
  6. Check Case: Use case:auto (default) for smart matching