Put an underscore before all digits in a string

I think what you’re missing is that \1 refers to the first capture in the regex match, and to create a capture you need to use parentheses in the regex:

julia> replace("x123y456", r"(\d+)" => s"_\1")
"x_123y_456"

(note the parentheses around \d+)

7 Likes