Please take a look at the following code:
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++));
}
The output of the above program is: a < b, c > d
But I actually expect a < b, b > c, c > d
.
Anything wrong with my regexp here?