Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't escape '$' in --replace text #1524

Closed
linuskr opened this issue Mar 19, 2020 · 2 comments
Closed

Can't escape '$' in --replace text #1524

linuskr opened this issue Mar 19, 2020 · 2 comments
Labels
doc An issue with or an improvement to documentation.

Comments

@linuskr
Copy link

linuskr commented Mar 19, 2020

What version of ripgrep are you using?

ripgrep 12.0.0
-SIMD -AVX (compiled)
+SIMD +AVX (runtime)

What operating system are you using ripgrep on?

Windows 10

Describe your question, feature request, or bug.

When using ripgrep's --replace option, '$' can't be used in the replacement text, because it is interpreted as the name of a capture group and cannot be escaped:
rg -iIN 'test([^:_$])' -r '$replacement_text$$1' outputs $1 instead of e.g. $replacement_text$!

Trying to escape the '$' does not work either:
rg -iIN 'test([^:_$])' -r '\$replacement_text\$$1' yields \\$1 instead.

@BurntSushi
Copy link
Owner

It can be escaped. Use $$ to write a literal $. It's documented here: https://docs.rs/regex/1.3.5/regex/struct.Captures.html#method.expand

It should be documented in the help text for the --replace flag though, so I'll mark this as a doc bug.

@BurntSushi BurntSushi added the doc An issue with or an improvement to documentation. label Mar 19, 2020
@linuskr
Copy link
Author

linuskr commented Mar 19, 2020

Didn't think about that, thank you for the quick response and ripgrep itself.

BurntSushi added a commit that referenced this issue May 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc An issue with or an improvement to documentation.
Projects
None yet
Development

No branches or pull requests

2 participants