import java.io.*;
import java.util.regex.*;
public class test
{
public static void main(String[] args)
{
String str = "go go";
String regex="\\b(?<Word>\\w+)\\b\\s+\\k<Word>\\b";
Matcher m=Pattern.compile(regex).matcher(str);
while(m.find()){
System.out.println(m.group());
}
}
}
import java.util.regex.*;
public class test
{
public static void main(String[] args)
{
String str = "go go";
String regex="\\b(?<Word>\\w+)\\b\\s+\\k<Word>\\b";
Matcher m=Pattern.compile(regex).matcher(str);
while(m.find()){
System.out.println(m.group());
}
}
}
public static void main(String args[]) {
String str=" go go";
String regex="\\b(\\w+)\\b\\s*\\1\\b";
Matcher m=Pattern.compile(regex).matcher(str);
while(m.find()){
System.out.println(m.group());
} }
}
\k<name> 命名捕获组反向引用
命名捕获组目前只有.NET和PHP等有限的几种语言支持,Java是不支持的
据说是在Java7.0中会提供对命名捕获组的支持,目前Java中只能使用普通捕获组