import java.io.*;
import java.util.regex.*;
public class test
{
public static void main(String[] args)
{
String str = "龙";
String regex="\\w";
Matcher m=Pattern.compile(regex).matcher(str);
while(m.find()){
System.out.println(m.group());
}
}
}
import java.io.*;
import java.util.regex.*;
public class test
{
public static void main(String[] args)
{
String str = "龙";
String regex="\\w\\w";
Matcher m=Pattern.compile(regex).matcher(str);
while(m.find()){
System.out.println(m.group());
}
}
}都没有打印结果,不是说\w以匹配任意汉字么
import java.util.regex.*;
public class test
{
public static void main(String[] args)
{
String str = "龙";
String regex="\\w";
Matcher m=Pattern.compile(regex).matcher(str);
while(m.find()){
System.out.println(m.group());
}
}
}
import java.io.*;
import java.util.regex.*;
public class test
{
public static void main(String[] args)
{
String str = "龙";
String regex="\\w\\w";
Matcher m=Pattern.compile(regex).matcher(str);
while(m.find()){
System.out.println(m.group());
}
}
}都没有打印结果,不是说\w以匹配任意汉字么
import java.io.*;
import java.util.regex.*;
public class RRR1
{
public static void main(String[] args)
{
String str = "3龙3";
String regex="\\w";
Matcher m=Pattern.compile(regex).matcher(str);
while(m.find()){
System.out.println(m.group());
}
}
}
输出
3
3分别截取了汉字两边的数。
import java.util.regex.*;
public class Test1
{
public static void main(String[] args)
{
String str = "龙的传人";
String regex="[\u4E00-\u9FA5]*";
Matcher m=Pattern.compile(regex).matcher(str);
while(m.find()){
System.out.println(1);
System.out.println(m.group());
}
}
} 结果
龙的传人