Skip to main content
4 of 4
added 10 characters in body
J.Doe
  • 2.6k
  • 11
  • 15

R, 83/72 bytes

Alt approach using regexps

If we're allowed a trailing newline, 72 bytes:

function(s,n)cat(gsub("([^
]*
)",r,gsub("([^
])",r<-strrep("\\1",n),s)))

Try it online!

Otherwise, 83 bytes:

function(s,n)write(rep(el(strsplit(gsub("([^\n])",strrep("\\1",n),s),"\n")),e=n),1)

Try it online!

J.Doe
  • 2.6k
  • 11
  • 15