fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.util.regex.*;
  4. class Main {
  5. public static void main(String[] args) {
  6. String input1 = "Request ECUReset for [*11 01]";
  7. String output1 = getBracketValue(input1);
  8. System.out.println(input1 + " --> " + output1);
  9.  
  10. String input2 = "Request ECUReset for [*11]";
  11. String output2 = getBracketValue(input2);
  12. System.out.println(input2 + " --> " + output2);
  13.  
  14. String input3 = "Request ECUReset for [*11 01 10]";
  15. String output3 = getBracketValue(input3);
  16. System.out.println(input3 + " --> " + output3);
  17. }
  18. private static String getBracketValue(String input) {
  19. Matcher m = Pattern.compile("(?<=\\[\\*)[^\\]]*(?=\\])").matcher(input);
  20. if (m.find()) {
  21. return m.group();
  22. }
  23. return null;
  24. }
  25. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
Request ECUReset for [*11 01] --> 11 01
Request ECUReset for [*11] --> 11
Request ECUReset for [*11 01 10] --> 11 01 10