Understanding the backlash parsing of ripgrep. #1585
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
It's because you have to escape the slash through two layers. The first is (presumably) your shell, where This is why almost all ripgrep examples involving this sort of thing use single quotes. On Unix, single quotes won't do any kind of interpolation and treat their contents literally. So you don't need to do any additional escaping. That is, on Unix, I'm not a Windows user, so I don't know what the equivalent syntax is. Does it have single quote syntax for literals? You might also consider using the Given those rules, I would expect As for I think your possible solutions to make this more sensible are:
Please keep in mind that I am not a Windows user. Most of what I'm saying here is mostly just guesswork based on your examples. Responses from more knowledgeable Windows users would be most welcome. |
Beta Was this translation helpful? Give feedback.
It's because you have to escape the slash through two layers. The first is (presumably) your shell, where
\\
needs to be used to express a\
. The second is the regex language itself. Since\
is a special character, it needs to be escaped. Thus, you need to combine\\
twice to search a literal slash.This is why almost all ripgrep examples involving this sort of thing use single quotes. On Unix, single quotes won't do any kind of interpolation and treat their contents literally. So you don't need to do any additional escaping. That is, on Unix,
rg '\\'
correctly searches for a\
.I'm not a Windows user, so I don'…