Expanding on this answer, using this regex (?<=\\G.{" + count + "})
; I would also like to modify the expression to not split words in the middle.
Example:
String string = "Hello I would like to split this string preserving these words";
if I want to split on 10 characters it would look like this:
[Hello I wo, uld like t, o split th, is string , preserving, these wor, ds]
Question:
Is this even possible using only regex
, or would a lexer or some other string manipulation be needed?
UPDATE
This is what I want to use it on:
+ -------------------------------------------JVM Information------------------------------------------ + | sun.boot.class.path : C:\Program Files\Java\jdk1.6.0_33\jre\lib\resources.jar;C:\Program Files\Java\ | | jdk1.6.0_33\jre\lib\rt.jar;C:\Program Files\Java\jdk1.6.0_33\jre\lib\sunrsasig | | n.jar;C:\Program Files\Java\jdk1.6.0_33\jre\lib\jsse.jar;C:\Program Files\Java | | \jdk1.6.0_33\jre\lib\jce.jar;C:\Program Files\Java\jdk1.6.0_33\jre\lib\charset | | s.jar;C:\Program Files\Java\jdk1.6.0_33\jre\lib\modules\jdk.boot.jar;C:\Progra | | m Files\Java\jdk1.6.0_33\jre\classes | + ---------------------------------------------------------------------------------------------------- +
The box surrounding it has the character limit minus the key width, however this does not look good. This example is also not the only use-case, i use that box for multiple types of information.