Skip to content

When doing replacement, why does $1 www$3 yield expected results but $1www$3 does not? #2974

Answered by BurntSushi
Goobyalus asked this question in Q&A
Discussion options

You must be logged in to vote

This is answered in the documentation. This case is specifically called out in the help for the -r/--replace flag:

-r REPLACEMENT, --replace=REPLACEMENT
    Replaces every match with the text given when printing results. Neither
    this flag nor any other ripgrep flag will modify your files.

    Capture  group  indices (e.g., $5) and names (e.g., $foo) are supported
    in the replacement string. Capture group indices are numbered based  on
    the  position  of the opening parenthesis of the group, where the left‐
    most such group is $1. The special $0 group corresponds to  the  entire
    match.

    The  name of a group is formed by taking the longest string of letters,
    number…

Replies: 1 comment 3 replies

Comment options

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

@BurntSushi
Comment options

@Goobyalus
Comment options

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