oprogfrogo
oprogfrogo

Reputation: 2074

Ruby - Making a newline within usage of gsub

I'm a bit stuck on this issue. I'm trying to make a newline using '\n'. I'm opening a file, then replacing the text, then writing it back as an html file:

replace = text.gsub(/aaa/, 'aaa\nbbb')

But this results in:
aaa\nbbb

I'm trying to make do:
aaa
bbb

Upvotes: 0

Views: 470

Answers (2)

steenslag
steenslag

Reputation: 80075

In single-quoted strings a backslash is just a backslash (except if it precedes another backslash or a quote). Use double quotes: "aaa\nbbb" .

Upvotes: 4

Related Questions