fork download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String helper = "985, 913, 123, SomeotherText, MoreText, MoreText";
  13. Pattern pattern = Pattern.compile("\\b\\d{3}");
  14. Matcher matcher = pattern.matcher(helper);
  15. String newtext = "";
  16.  
  17. while (matcher.find()) {
  18. newtext = "Number: " + matcher.group() + "\n"+ newtext;
  19. helper = helper.replaceAll(matcher.group() + ", ","");
  20. }
  21. newtext = newtext + "________________\n"+ helper;
  22. System.out.println(newtext);
  23. }
  24. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
Number: 123
Number: 913
Number: 985
________________
SomeotherText, MoreText, MoreText