Search Examples
Learn and walkthrough some of the handy Code Search examples.
Sourcegraph Search Examples on Github Pages
Check out the Sourcegraph Search Examples site for filterable search examples with links to results on sourcegraph.com.
Below are some additional examples that search repositories on Sourcegraph.com, our open source code search solution for GitHub and GitLab. You can copy and adapt the following search queries for use on your company’s private instance.
Search through all the repositories in an organization
context:global r:hashicorp/ terraformSearch a subset of repositories in an organization by language
context:global r:hashicorp/vault* lang:yaml terraformSearch for one term or another in a specific repository
context:global r:hashicorp/vault$ print( OR log(Find private keys and GitHub access tokens checked in to code
(-----BEGIN [A-Z ]*PRIVATE KEY------)|(("gh|'gh)[pousr]_[A-Za-z0-9_]{16,}) patternType:regexp case:yesRecent security-related changes on all branches
type:diff repo:@*refs/heads/ after:"5 days ago"
\b(auth[^o][^r]|security\b|cve|password|secure|unsafe|perms|permissions)Admitted hacks and TODOs in app code
-file:\.(json|md|txt)$ hack|todo|kludge|fixmeRemoval of TODOs in the repository commit log
repo:^github\.com/sourcegraph/sourcegraph$ type:diff select:commit.diff.removed TODOtype:diff after:"1 week ago" \.subscribe\( lang:typescriptFind multiple terms in the same file, like testing of HTTP components
repo:github\.com/sourcegraph/sourcegraph$ (test AND http AND NewRequest) lang:goRecent quality related changes on all branches (customize for your linters)
repo:@*refs/heads/:^master type:diff after:"1 week ago" (eslint-disable)file:package.json type:diff after:"1 week ago"Files that are Apache licensed
licensed to the apache software foundation select:fileOnly repositories with recent dependency changes
file:package.json type:diff after:"1 week ago" select:repoSearch changes in a files that contain a keyword
repo:^github\.com/sourcegraph/sourcegraph$ type:diff file:contains.content("golang\.org/x/sync/errgroup") .GoWhen to use regex search mode
Sourcegraph's default literal search mode is line-based and will not match across lines, so regex can be useful when you wish to do so:
Matching multiple text strings in a file
repo:^github\.com/Parsely/pykafka$ Not leader for partitionRegex searches are also useful when searching boundaries that are not delimited by code structures:
Finding css classes with word boundary regex
repo:^github\.com/sourcegraph/sourcegraph$ \bbtn-secondary\bWhen to use structural search mode
Use structural search when you want to match code boundaries such as () or :
Finding try catch statements with varying content
repo:^github\.com/sourcegraph/sourcegraph$
try { :[matched_statements] } catch { :[matched_catch] }