More
Writing search queries
Sourcebot uses a powerful regex-based query language that enabled precise code search within large codebases.
Syntax reference guide
Queries consist of space-separated regular expressions. Wrapping expressions in ""
combines them. By default, a file must have at least one match for each expression to be included.
Example | Explanation |
---|---|
foo | Match files with regex /foo/ |
foo bar | Match files with regex /foo/ and /bar/ |
"foo bar" | Match files with regex /foo bar/ |
Multiple expressions can be or’d together with or
, negated with -
, or grouped with ()
.
Example | Explanation |
---|---|
foo or bar | Match files with regex /foo/ or /bar/ |
foo -bar | Match files with regex /foo/ but not /bar/ |
foo (bar or baz) | Match files with regex /foo/ and either /bar/ or /baz/ |
Expressions can be prefixed with certain keywords to modify search behavior. Some keywords can be negated using the -
prefix.
Prefix | Description | Example |
---|---|---|
file: | Filter results from filepaths that match the regex. By default all files are searched. | file:README - Filter results to filepaths that match regex /README/ file:"my file" - Filter results to filepaths that match regex /my file/ -file:test\.ts$ - Ignore results from filepaths match regex /test\.ts$/ |
repo: | Filter results from repos that match the regex. By default all repos are searched. | repo:linux - Filter results to repos that match regex /linux/ -repo:^web/.* - Ignore results from repos that match regex /^web\/.* |
rev: | Filter results from a specific branch or tag. By default only the default branch is searched. | rev:beta - Filter results to branches that match regex /beta/ |
lang: | Filter results by language (as defined by linguist). By default all languages are searched. | lang:TypeScript - Filter results to TypeScript files-lang:YAML - Ignore results from YAML files |
sym: | Match symbol definitions created by universal ctags at index time. | sym:\bmain\b - Filter results to symbols that match regex /\bmain\b/ |
context: | Filter results to a predefined search context. | context:web - Filter results to the web context-context:pipelines - Ignore results from the pipelines context |