fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.*;
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String sentence = "4-2-3-1";
  11. Pattern pCode = Pattern.compile("\\b\\d(?:\\s?-\\s?\\d){2,}\\b");
  12. Matcher mCode = pCode.matcher(sentence);
  13. while (mCode.find()) {
  14. mCode.appendReplacement(sb, mCode.group().replace("-", " "));
  15. }
  16. mCode.appendTail(sb);
  17. System.out.println(sb);
  18. }
  19. }
Success #stdin #stdout 0.07s 33712KB
stdin
Standard input is empty
stdout
4 2 3 1