Skip to content

Understanding the backlash parsing of ripgrep. #1585

Answered by BurntSushi
DasOhmoff asked this question in General
Discussion options

You must be logged in to vote

As you can see, I seem to have to escape the backslashes inside the quotes.

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'…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@DasOhmoff
Comment options

@BurntSushi
Comment options

@DasOhmoff
Comment options

Answer selected by BurntSushi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants