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

Replace with a literal dollar symbol followed by another character #129

Closed
tyilo opened this issue May 18, 2021 · 5 comments · Fixed by #207
Closed

Replace with a literal dollar symbol followed by another character #129

tyilo opened this issue May 18, 2021 · 5 comments · Fixed by #207
Assignees
Labels
M-needs triage Meta: Maintainer label me!

Comments

@tyilo
Copy link

tyilo commented May 18, 2021

I want to replace \w+ with $a.

Nothing seems to work using latest git version (4ccc522):

$ echo foo | sd '\w+' '$a'

$ echo foo | sd '\w+' '\$a'
\
$ echo foo | sd '\w+' '\\$a'
\
$ echo foo | sd '\w+' '\\\$a'
\
$ echo foo | sd '\w+' '\\\\$a'
\
$ echo foo | sd '\w+' '\\\\\$a'
\\\

Using string mode works, but then I can't use regex in the search:

$ echo foo | sd -s 'foo' '$a'
$a
@learnbyexample
Copy link

learnbyexample commented May 18, 2021

$ echo foo | sd '\w+' '$$a'
$a
  • You need to use \w+ to match one or more word characters. w+ will match one or more w characters.
    • Edit: just noticed that you mention \w+ in the first line, I commented based on code samples which uses w+ only.
  • Use $$ to indicate literal $ character in replacement section.

@tyilo
Copy link
Author

tyilo commented May 18, 2021

  • Use $$ to indicate literal $ character in replacement section.

Ah, could this be documented in --help?

@learnbyexample
Copy link

Just checked the help page and seems it isn't documented. I knew about $$ from using ripgrep. Perhaps you could submit the PR.

@balupton
Copy link

balupton commented Dec 2, 2021

sd and ripgrep both use rust's regex implementation, so anything there is supported here:

https://docs.rs/regex/latest/regex/

@ruudk
Copy link

ruudk commented May 22, 2022

Created a PR to document it in the readme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
M-needs triage Meta: Maintainer label me!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants