3 ms·
ripgrep is a modern faster grep in Rust, some cons, many pros. It'll do capture groups with search | replace # remove square brackets that surround digit
by defrost 4y ago
ripgrep is a modern faster grep in Rust, some cons, many pros.
It'll do capture groups with search | replace
# remove square brackets that surround digit characters
$ echo '[52] apples [and] [31] mangoes' | rg '\[(\d+)]' -r '$1'
52 apples [and] 31 mangoes
- asicsp 4y agoPleasantly surprised to see an example from my ebook :) Add `-o` option to get only the digits: $ echo '[52] apples [and] [31] mangoes' | rg -o '\[(\d+)]' -r '$1' 52 31
- defrost 4y agoCongratulations (?) for making the top five google results for "ripgrep capture groups" [1]. I cite sources way more often than not, this time I got lazy after dithering over whether to go with the definitive ripgrep source page [2] or a decent looking third party(?) tutorial .. pressed for time I did neither. [1] https://learnbyexample.github.io/learn_gnugrep_ripgrep/ripgrep.html https://learnbyexample.github.io/learn_gnugrep_ripgrep/ripgr... [2] https://github.com/BurntSushi/ripgrep https://github.com/BurntSushi/ripgrep