fork(3) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.regex.Matcher;
  4. import java.util.regex.Pattern;
  5.  
  6. /* Name of the class has to be "Main" only if the class is public. */
  7. class Ideone
  8. {
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11. final String regex = "^(\\S+) pid: (\\d+) ([^\\\\\\s]+)\\\\(.+)";
  12. final String processDetails = "Skype.exe pid: 1404 WATCHOUT\\tofetopo";
  13. String processName = null;
  14. String processID = null;
  15. String computerName = null;
  16. String currentUser = null;
  17.  
  18. final Pattern pattern = Pattern.compile(regex);
  19. final Matcher matcher = pattern.matcher(processDetails);
  20.  
  21. if (matcher.find()) {
  22. processName = matcher.group(1);
  23. processID = matcher.group(2);
  24. computerName = matcher.group(3);
  25. currentUser = matcher.group(4);
  26. }
  27.  
  28. System.out.println(processName);
  29. System.out.println(processID);
  30. System.out.println(computerName);
  31. System.out.println(currentUser);
  32. }
  33. }
Success #stdin #stdout 0.05s 711168KB
stdin
Standard input is empty
stdout
Skype.exe
1404
WATCHOUT
tofetopo