fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  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 regex = "\\[([0-9]+)\\]$";
  13. String string = "[52,52,73,52],[23,32],[40]";
  14. Pattern pattern = Pattern.compile(regex);
  15. Matcher matcher = pattern.matcher(string);
  16. if(matcher.find()) {
  17. System.out.println(matcher.group(1)); // 40
  18. }
  19. }
  20. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
40