Rg

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the unix category.

Last Updated: 2022-05-26

RG

Matching groups

Say I have some code like this

translate('name')
translate('person')

How to get the translation strings inside the function calls?

# Just get bit inside the `translate` function scattered throughout the code
$ rg --only-matching "translate\('(.+)'\)" -r '$1'
# - `-r` is group number
# `--only-matching` removes the rest of the line

Skipping the file header divisions in the output

rg --no-header needle haystack

Searching

Use a .ignore file in your root directory to override how ripgrep uses the gitignore file

e.g.

# Ensure the ripgrep actually searches node_modules e.g. in nvim
!node_modules/