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以匹配任意汉字么

解决方案 »

  1.   

    匹配不了,你试试,好像说JAVA没提供这个功能我是用命令符运行程序
      

  2.   


    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分别截取了汉字两边的数。
      

  3.   

    package day01;import java.io.*; 
    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()); 
                
            } 
        } 
    } 结果
    龙的传人