Doing a literal search with ripgrep is easy and can be done with the -F parameter.

To search for a string literal and not a regex, use:

rg -F 'my string literal'

Searching for a string literal is useful when you have to look for a string that ripgrep would interpret as regex (this behavior is by default). This is often the case when searching for snippets of code. For example,

rg -F 'main()'

The search query 'main' would be interpreted as regex if -F is not used.

ripgrep in PowerShell

If you are in PowerShell I recommend to use single quotes than double quotes, otherwise PowerShell will interpret what is in the double quotes.

However, evaluating the query in the double quotes sometimes is desired, if we want to search from the contents inside the variable. In that case we can use double quotes:

$resultsFromElsewhere = 'banana'
# the following line is equivalent to 
# rg -F 'banana'
rg -F "$resultsFromElsewhere"

πŸ„β€πŸŸ«πŸ“– Fun fact: ripgrep parameter -F is equivalent to Window’s findstr /C parameter.

Happy Searching πŸ”Ž