Replace with count match #2995
-
For example, I have Markdown with headers root
# test1
... some text
##test2 squeezed
... some text
### tost3 excess spaces I am trying to replace headers with spaces to have root
test1
... some text
test2 squeezed
... some text
tost3 excess spaces So how can I improve |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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 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. ripgrep is not a good tool for formatting. But, you can kinda make your example work with ripgrep. You can take advantage of the fact that the number of
The output shown above doesn't match the expected output you've shown, but that seems to be because your expected output is inconsistent with your description of the behavior you want. I chose to respect your description instead of your expected output. |
Beta Was this translation helpful? Give feedback.
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.…