Search code examples
regexsublimetext3

How to break long lines into five-character lines


I want to break long lines into five characters and ignore short lines:

aaa
bbbbbbb
cc
dddddddddddd

into

aaa
bbbbb
bb
cc
ddddd
ddddd
dd

I found way to find only long lines:

^(.{5,}) 

but I've no idea how to break it to five character lines several times.

Another way is: find .{0,5}(\s*|$) and replace with $0\n. It works but after each previous line it creates a new empty line, even after short lines.

I'm testing in Sublime Text 3, so maybe some Sublime plugin could do it as well?


Solution

  • A line break can be inserted like this :

    Find ([^\r\n]{5}) replace $1\r\n

    https://regex101.com/r/dTeMbq/1