用哪个正则表达式可以过滤掉非中文的内容,
这里的中文指的是所有的汉字,但不包括中文
的标点

解决方案 »

  1.   

    添加过滤器。pattern = "[\u4e00-\u9fa5]*"
      

  2.   

    这是我用过的代码,楼主改一下就可以用了,/**
     * 处理含有中文字符的url
     * 
     * @param url
     * @return 新的url
     */
    public static String enCodeURL(String url, String code) {
    if (!StringUtil.isFine(url))
    return null;
    Pattern pattern = Pattern.compile(
    "[\u300a\u300b]|[\u4e00-\u9fa5]|[\uFF00-\uFFEF]",
    Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
    Matcher m = pattern.matcher(url);
    if (m.find()) {
    int get = m.start();
    String suburl = url.charAt(get) + "";
    String encodesuburl = "";
    try {
    encodesuburl = URLEncoder.encode(suburl, code);
    } catch (Exception e) {
    }
    url = url.replaceAll(suburl, encodesuburl);
    url = enCodeURL(url, code);
    }
    url = url.replaceAll(" ", "20%");
    return url;
    }