Replacement of words and transition to a new Java line
-
There's some text in the format.
String
, we need to put a new line on every five points.\n
and replace "Today" with "Tomorrow."Help with regexp, but I'll be glad if you can do something else.
-
Replace
Today
♪Tomorrow
Elementary methodString.replaceAll
♪ It's so obvious that there's no mention. And the regular for the first part of the assignment is more interesting. For example, it is possible to:s.replaceAll("((.*?\\.){5})", "$1\n");
Insufficient this decision will take into account the points and inside of the word (e.g., it may break the reduction
т.е.
) We will therefore take advantage of the fact that, in most languages, there is a gap at the end of the sentence:s.replaceAll("((.*?\\.\\s+){5})", "$1\n");
The side effect of the second decision is that it will remove the gaps at the beginning of the rolling lines rather than the first solution. Now the gaps remain at the end of the line. Removing them will be harder, but it's possible:
s.replaceAll("((.*?\\.\\s+){4}(.*?\\.))\\s+", "$1\n");