请看下面的代码:
public static void main(String[] args) {
String s = "a < b > c > d";
String regex = "(\\w\\s*[<>]\\s*\\w)";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(s);
int i = 0;
while (m.find()) System.out.println(m.group(i++));
}
上述程序的输出是:a < b, c > d
但我其实很期待a < b, b > c, c > d
。
我的正则表达式有什么问题吗?