Skip to content

Instantly share code, notes, and snippets.

@rattrayalex
Created July 30, 2021 02:19
Embed
What would you like to do?
Ripgrep ignore/exclude files that match a certain string

Say you want to search for a certain string, but exclude files which match another pattern.

PATTERN_TO_EXCLUDE="bad.+words"
DIR_TO_SEARCH=foo/bar
PATTERN_TO_FIND="good.+good"

rg $PATTERN_TO_FIND --stats $(rg $PATTERN_TO_EXCLUDE --files-without-match $DIR_TO_SEARCH)

A files which does contain "good regex" will be matched, unless it also contains "bad regex".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment