Hacker News new | ask | show | jobs
by cormacrelf 241 days ago
How about -F -regexthatlookslikeaflag? Verbatim, that errors out as the command line parsing tries to interpret it as a flag. If you don’t have -F, then you can escape the leading hyphen with a backslash in a single quoted string: '\-regex…', but then you don’t get fixed string search. And -F '\-regex…' is a fixed string search for “backslash hyphen r e g e x”. The only way is to manually escape the regex and not use -F.

I think maybe a syntax like -F=-regex would work.

2 comments

Yeah, that's a good call out. You would need `rg -F -e -pattern`.
The convention is use use -- to denote the end of options in command-line tools - anything after that is parsed as a normal argument even if it starts with a dash. If rg doesn't support that it should.
It has since day 1. And you can use the `-e/--regexp` flag too, just like grep.