sd
sd copied to clipboard
Replace with a literal dollar symbol followed by another character
I want to replace \w+ with $a.
Nothing seems to work using latest git version (4ccc52203afda466a409f1b0835798ebdb2ee622):
$ 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
$ echo foo | sd '\w+' '$$a'
$a
- You need to use
\w+to match one or more word characters.w+will match one or morewcharacters.- Edit: just noticed that you mention
\w+in the first line, I commented based on code samples which usesw+only.
- Edit: just noticed that you mention
- Use
$$to indicate literal$character in replacement section.
- Use
$$to indicate literal$character in replacement section.
Ah, could this be documented in --help?
Just checked the help page and seems it isn't documented. I knew about $$ from using ripgrep. Perhaps you could submit the PR.
sd and ripgrep both use rust's regex implementation, so anything there is supported here:
https://docs.rs/regex/latest/regex/
Created a PR to document it in the readme.