Skip to content

Replace with count match #2995

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

You must be logged in to vote

As I said in #2988, ripgrep doesn't come with arbitrary flexibility for customizing the output. This needs to be done via post-processing somehow. Sometimes you can do that with ripgrep, but it is fundamentally limited because it doesn't let you express arbitrary logic with its -r/--replace field. All you can do is provided a fixed string with some references into the matched part of the original pattern. You can't do things like, "insert N number of spaces, where N is the number of # characters matched in a capture group."

For these kinds of tasks, tools like awk are probably better suited. ripgrep is a tool for finding things, but you're trying to use it as a tool for formatting things.…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
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