有没有办法在java中打印出正则表达式模式的前瞻部分?
String test = "hello world this is example";
Pattern p = Pattern.compile("\\w+\\s(?=\\w+)");
Matcher m = p.matcher(test);
while(m.find())
System.out.println(m.group());
这个片段打印出来:
你好
世界
这
是
我想要做的是成对打印单词:
你好世界
世界这
是
例子
我怎样才能做到这一点?