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.io.IOException;
  7. import java.util.regex.Matcher;
  8. import java.util.regex.Pattern;
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15. Pattern p = Pattern.compile("(\\d+)\\.\\s([A-Z,\\s]+)");
  16. Matcher m = p.matcher("Answers 1. D 2. C 3. E 4. D 5. E 6. E 7. C");
  17. while(m.find())
  18. System.out.println(m.group(0)+"_"+m.group(1)+"_"+m.group(2));
  19. }
  20. }
Success #stdin #stdout 0.11s 320256KB
stdin
Standard input is empty
stdout
1. D _1_D 
2. C _2_C 
3. E _3_E 
4. D _4_D 
5. E _5_E 
6. E _6_E 
7. C_7_C