fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.regex.*;
  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 strs[] = {"000001010016C02AB 111*", "000001010016C02 111H", "000001010016C 111 ", "901509010012V 154 "};
  13. Pattern p = Pattern.compile("(.{11})[0-9](.{5}).{5}(.*)");
  14. for (String s: strs) {
  15. StringBuffer result = new StringBuffer();
  16. Matcher m = p.matcher(s);
  17. if (m.matches()) {
  18. m.appendReplacement(result, m.group(1) + "," + m.group(2).trim() + "," + m.group(3));
  19. }
  20. System.out.println(result.toString());
  21. }
  22.  
  23. }
  24. }
Success #stdin #stdout 0.1s 27900KB
stdin
Standard input is empty
stdout
00000101001,C02AB,*
00000101001,C02,H
00000101001,C, 
90150901001,V,