I would like to split a String using regex just like in this example, but in my case I want that each words in a new line will not exceed X characters.
So the following code doesn't do the trick since it finds every instance of at least X non-newline characters (and not max X).
s = s.replaceAll("(.{" + x + ",}?)\\s+", "$1\n"); I can easily do this using other methods, but I would like to do it using a REGEX
(.{0, " + x + "})instead?