How does one put a new line (\n) in a substitution string? e.g.:
println(replace("test string", r"(test string)" => s"\1 \n line 2"))
Id like it to return:
test string
line 2
But I get:
Bad replacement string: \1 \n line 2
If I double escape the new line, I just get the escaped literal:
println(replace("test string", r"(test string)" => s"\1 \\n line 2"))
test string \n line 2
(Obviously toy example, I recognize not super motivated. But I have use case where I want to use group names (so need a substitution string) and new linesβ¦)
Not sure you can do it with the syntactic sugar of s"...", but at least what you want can be achieved using the standard SubstitutionString constructor:
julia> println(replace("test string", r"(test string)" => SubstitutionString("\\1\nline 2")))
test string
line 2