To get you started, it will look something like this. This is the most basic regex that is looking for exactly 5 digits as a PID.
Obviously, we are assuming here that a PID is always 5 digits, and that every sequence of 5 digits is going to be a PID.
If you want to get more fool-proof, you might play around with regex searching for the "pid" prefix and some suffix, and then trimming that String accordingly.
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
static String PATTERN = "[0-9]{5}";
static String test = "pkill -f ./scene\r\n" +
"scene killed (pid 11619)\r\n" +
"scene killed (pid 31533)";
public static void main(String[] args) {
List<String> matches = new ArrayList<String>();
Matcher m = Pattern.compile(PATTERN).matcher(test);
while (m.find()) matches.add(m.group());
System.out.println(matches);
}
}
Gives us the output:
[11619, 31533]