Skip to content

Latest commit

 

History

History
25 lines (18 loc) · 859 Bytes

find-occurrences-of-multiple-values-with-ripgrep.md

File metadata and controls

25 lines (18 loc) · 859 Bytes

Find Occurrences Of Multiple Values With Ripgrep

Let's say I have a several values that show up throughout the files in my project. They are Valid, Restricted, Refunded, Disputed, and Banned.

I want to find all occurrences of each of these values.

This can be done with rg (ripgrep) and a bit of regex.

rg "\b(Valid|Restricted|Refunded|Disputed|Banned)\b"

This uses \b on both ends to indicate word boundaries. This ensures it matches on Valid without also matching on Validate. It then wraps all the options in parentheses separated by | which says, "match on this word, this word, ..., or this word".

I can even take this a step further by only matching on quoted instances of these words like so:

$ rg "[\"']\b(Valid|Restricted|Refunded|Disputed|Banned)\b[\"']"