Say I have an arbitrary string that has x number of characters. How can I insert a newline char in the string for every y characters? I just want to wrap the string, so that this:
Say I have an arbitrary string that has x number of characters. How can I insert a newline char in the string for every y characters? I just want to wrap the string, so that this:
What this does is, every 8 characters are matched (with .{8}), and then '$&' in the second argument represents the whole substring that was matched. So, just tack on a \n to the end, and every 8 characters will be replaced with those 8 characters plus a newline. You can also insert matched groups like this, among other things - see the docs.