How can one change the following text
The quick brown fox jumps over the lazy dog.
to
The quick brown fox +
jumps over the +
lazy dog.
using regex?
UPDATE1
A solution for Ruby is still missing... A simple one I came to so far is
def textwrap text, width, indent="\n"
return text.split("\n").collect do |line|
line.scan( /(.{1,#{width}})(\s+|$)/ ).collect{|a|a[0]}.join indent
end.join("\n")
end
puts textwrap 'The quick brown fox jumps over the lazy dog.', width=19, indent=" + \n "
# >> The quick brown fox +
# >> jumps over the lazy +
# >> dog.