一个简单的正则问题
String script = "a 1 c a 2 c a 3 c a 4 c a 5 c a 6 c ";
要用正则依次查出a - c的数
结果要这样的
a 1 c
a 2 c
a 3 c
a 4 c
a 5 c
a 6 c
------解决方案-------------------- String script = "a 1 c a 2 c a 3 c a 4 c a 5 c a 6 c ";
java.util.regex.Pattern pattern = Pattern.compile( "a \\d c ");
Matcher matcher = pattern.matcher(script);
while (matcher.find()) {
int start = matcher.start();
int end = matcher.end();
String match = script.substring(start, end);
System.out.println(match);
}