我想从字符串中提取2个数字。 我的示例代码:java中的模式匹配:从字符串文字中提取数字
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
public static int returnInt(String pattern, String inputString) {
Pattern intPattern = Pattern.compile(pattern);
Matcher matcher = intPattern.matcher(inputString);
matcher.find();
String input = matcher.group(0);
return Integer.parseInt(input);
}
public static void main(String[] args) {
System.out
.println(returnInt(
"\\d+",
"The following DTE jobs have been submitted to ServerFarm for execution. (farm showjobs -d -j 12774076) can be used to monitor job status. The output format is JobID : TopoName : TopoAlias : JobStatus. (The initial job status is listed in brackets. If job status is FAILED, then the job can not be run at all! Otherwise please check job status periodically.) :21554030 : IDM_INSTALLER_1H1N_REL11 : IDM_INSTALLER_1H1N_REL11 : WAITING (Being queueed on server farm)"));
}
}
我想要的输出来为:12774076和21554030,但产量只有12774076 请帮助!
把matches.find()和在一个循环中提取数据的逻辑。 – nhahtdh 2014-09-19 10:03:47