Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • \$\begingroup\$ I just love this approach, but you can use . instead of [^] since you only need to skip non-newline characters to find a newline, which saves 2 bytes. \$\endgroup\$ Commented Jan 1, 2017 at 18:52
  • \$\begingroup\$ I don't think the ^ is necessary in the final regex, because any \n is already at the beginning of the string anyway, so that saves another byte. \$\endgroup\$ Commented Jan 1, 2017 at 18:54
  • \$\begingroup\$ I've come up a way to golf the '$&'+' '.repeat(n). Basically that expression is just $& but with a space added each call, which is trivial to implement recursively - replace n=0 with r='$&' and f(z,n+1) with f(z,r+' ') and then r is the desired replacement string. If I've counted correctly that saves 12 bytes. \$\endgroup\$ Commented Jan 1, 2017 at 18:58