Search examples
Below are 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.
See search query syntax reference.
-
Recent 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|fixme
-
New usages of a function
type:diff after:"1 week ago" \.subscribe\( lang:typescript
-
Recent quality related changes on all branches (customize for your linters)
repo:@*refs/heads/:^master type:diff after:"1 week ago" (eslint-disable)
-
Recent dependency changes
file:package.json type:diff after:"1 week ago"
When 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 partition
Regex 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\b
When 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] }