how do I search for a pattern starting with "-"? #1560
-
What version of ripgrep are you using?macOS homebrew: also on Windows precompiled: How did you install ripgrep?macOS: homebrew What operating system are you using ripgrep on?macOS 10.14.6 Describe your bug.Trying to use rg to search for a literal string that starts with a '-', specifically markdown style check boxes '- [ ]'. What are the steps to reproduce the behavior?
or
Running the search by escaping the leading dash works fine, but defeats the purpose of using -F in my opinion. What is the actual behavior?Normal and debug output are the same.
What is the expected behavior?rg should have searched the literal string '- [ ]' in the current directory. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
This is correct and expected behavior. The
So you'll want
This is a different search. There is no escaping when using
Note that grep has the same exact behavior here and the exact same work-arounds. |
Beta Was this translation helpful? Give feedback.
-
Moved this to a discussion, since this is more of a question of behavior even though it was reported as a bug. |
Beta Was this translation helpful? Give feedback.
This is correct and expected behavior. The
-F
flag is a red herring here. If your pattern starts with a-
, then you must either precede it with the-e
flag or use--
to indicate that all subsequent arguments are positional. This is documented in the man page:So you'll want
rg -F -e '- [ ]'
orrg -F -- '- [ ]'
.This is a different search. There is no escaping when using
-F
, so if you use\- [ ]
, then you'll actually be searching for a literal\\
followed by a-
: