fork download
  1. import java.util.regex.*;
  2. class M{
  3. static String c(String s){
  4. Matcher m = Pattern.compile("(.*?)(\\d+)(.*)").matcher(s);
  5. s = "";
  6. for(int i = 0; i < 3;){
  7. if(m.matches()){
  8. s += m.group(++i) + " ";
  9. }
  10. }
  11. return s;
  12. }
  13.  
  14. public static void main(String[] a){
  15. System.out.println(c("UK7898S14"));
  16. System.out.println(c("cphDK1234CYELLOWS14QGOOD"));
  17. }
  18. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
UK 7898 S14 
cphDK 1234 CYELLOWS14QGOOD