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.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main(String[]args) {
  12. Pattern p = Pattern.compile("Q(\\d+)");
  13. Matcher m = p.matcher("ansQaInput_Q1229_F1224");
  14. int counter = 0;
  15.  
  16. System.out.println("group: " + m.group(1));
  17.  
  18. }
  19. }
Runtime error #stdin #stdout #stderr 0.1s 320320KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.lang.IllegalStateException: No match found
	at java.util.regex.Matcher.group(Matcher.java:536)
	at Ideone.main(Main.java:16)