With grep
I can search for the start and end of a word with
grep -e '\<leg\>' <where to search>
this would find I have a leg.
but not play allegro here
.
Ripgrep (0.10.0) does not seem to support this way of writing this regular expression. My question thus is:
How to "grep" for occurrences at the begin/end of a word with ripgrep
?
(Nearly what you'd find in ripgrep's man page, so pipe it into a pager!) -i/--ignore-case: When searching for a pattern, ignore case differences. That is rg -i fast matches fast, fASt, FAST, etc.
Ripgrep is a command line tools that searches patterns under your current directory, like the good old grep, but with faster speed. In this post, I list some of the commonly-used flags for ripgrep.
Here, ripgrep limited its search to the src directory. Another way of doing this search would be to cd into the src directory and simply use rg 'fn write\ (' again. After recursive search, ripgrep's most important feature is what it doesn't search.
In this case, the recursive searches results will not consider binary files and hidden files/directories. ripgrep shares a DNA footprint with popular search tools like grep, find, ack, and The Silver Searcher.
ripgrep doesn't support the \<
and \>
word boundaries, which specifically only match the start and end of a word, respectively. ripgrep does however support \b
, which matches a word boundary anywhere. In this case, it's good enough for your specific example:
$ echo 'play allegro here' | rg '\bleg\b'
$ echo 'I have a leg.' | rg '\bleg\b'
I have a leg.
ripgrep also supports grep's -w
flag, which effectively does the same thing in this case:
$ echo 'play allegro here' | rg -w leg
$ echo 'I have a leg.' | rg -w leg
I have a leg.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With