fork(8) download
  1. import java.util.*;
  2. import java.util.regex.*;
  3. import java.lang.*;
  4. import java.io.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String s = "Min value = 5000 km";
  11. // A Capturing Group
  12. Matcher m = Pattern.compile("value\\s*=\\s*(\\d+)").matcher(s);
  13. if(m.find()) {
  14. System.out.println(m.group(1));
  15. }
  16. // A constrained width lookbehind
  17. m = Pattern.compile("(?<=value\\s{0,10}=\\s{0,10})\\d+").matcher(s);
  18. if(m.find()) {
  19. System.out.println(m.group());
  20. }
  21.  
  22. }
  23. }
Success #stdin #stdout 0.06s 2841600KB
stdin
Standard input is empty
stdout
5000
5000