正则表达式获取字符串匹配的内容

public static void main(String[] args) {
    String str="#你好啊#就离开噶快就勾搭上了#快跑啊~#阿斯蒂芬 #都是# asdf";
    String rex ="#[^#]+#";
    Pattern pat = Pattern.compile(rex);
    Matcher mat = pat.matcher(str);
    while(mat.find()) {
        System.out.println(mat.group(0));//m.group(1)不包括这两个字符
    }
}

 

posted @ 2017-09-18 16:17  __Ant  阅读(2967)  评论(0编辑  收藏  举报