【发布时间】:2011-07-28 06:37:23
【问题描述】:
有没有办法在 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());
这个 sn-p 打印出来:
你好
世界
这
是
我想要做的是成对打印单词:
你好世界
世界这个
这个 是
是例子
我该怎么做?
【问题讨论】:
标签: java regex pattern-matching regex-lookarounds