fork(2) download
  1. import java.lang.*;
  2. import java.io.*;
  3. import java.util.regex.*;
  4.  
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String path = "/Systems/lenovo/";
  11. Pattern p = Pattern.compile("(?:\\/[^\\/]+)");
  12. Matcher m = p.matcher(path);
  13.  
  14. if(m.find()) {
  15. System.out.println(m.group(0));
  16. }
  17. p = Pattern.compile("(?:\\/[^\\/]+){1}(?=\\/$)");
  18. m = p.matcher(path);
  19. if(m.find()) {
  20. System.out.println(m.group(0));
  21. }
  22.  
  23. }
  24. }
Success #stdin #stdout 0.1s 320512KB
stdin
Standard input is empty
stdout
/Systems
/lenovo