There is a line:

Runaway Train SOUL ASYLUM or Fading Like A Flower ROXETTE

As in Java, using a regular expression, convert (for the first word in which all capital letters) to:

SOUL ASYLUM - Runaway Train

ROXETTE - Fading Like A Flower

  • Ie there is a line in which a part of words is lowercase and a part is written in capital letters and they need to be changed in some places? - Artem Konovalov
  • Yes, swap the performer and the name of the track, maybe such a line - Promise Me MARSHAL Alexander, make MARSHAL Alexander - Promise Me. - Oleg Glazunov
  • And why do you need to do this exactly regular? So that life does not seem honey? - zed
  • advise another solution) - Oleg Glazunov
  • Start scanning character by character from the end of the line. Until you find the first lowercase letter, save the characters in the substring А , and after the lowercase appears and to the end of the line (or rather, before it starts), save in the substring B So in A you will have a performer, and in B - the name. - zed

1 answer 1

Here is my solution:

 private static String revert(String content) { Pattern pattern = Pattern.compile("[\\p{IsUppercase}]{2,}", Pattern.UNICODE_CASE); Matcher matcher = pattern.matcher(content); if (matcher.find()) { int index = matcher.start(); return content.substring(index) + " - " + content.substring(0, index); } return null; }