中文正则匹配

中文汉字的unicode范围:\u4e00-\u9fa5

全角字符的范围是:\ufe30-\uffa0

匹配双字符:[^\x00-\xff]

匹配空行的正则表达式:n[s| ]*r

匹配HTML标记的正则表达式:/<(.*)>.*</1>|<(.*) />/

匹配首尾空格的正则表达式:(^s*)|(s*$)
示例代码:
import java.util.regex.*;
public class Main{
    public static void main(String args[]){
        String str  = "我是fuc";
        String res = str.replaceAll("[\u4e00-\u9fa5]","*");
        Pattern p = Pattern.compile("[\u4e00-\u9fa5]+");
        Matcher matcher = p.matcher(str);
        matcher.find();
        String res=matcher.group();
        System.out.println(res);
    }
}
输出结果:
我是

 

 
posted @ 2015-04-26 15:31  湖心北斗  阅读(287)  评论(0编辑  收藏  举报