正则表达式拆分字符串

来源:互联网 发布:天谕业刹捏脸数据下载 编辑:程序博客网 时间:2024/05/17 02:21

今天遇到这样一个问题,对一个字符串按照某个分隔符进行分割,要求用正则表达式,不能用split

import java.util.regex.Matcher;import java.util.regex.Pattern;public class RegexTest {    public static void main(String[] args) {        String str = "hjg^^xgvj^^hsx^^hsjxgd^^udeggduejdehx^^exded^^ueue";        String re = "(?:([^\\^\\^]))+";        Pattern p = Pattern.compile(re, Pattern.CASE_INSENSITIVE);        Matcher m = p.matcher(str);        while(m.find()){            System.out.println(m.group());        }    }}

结果为:

hjgxgvjhsxhsjxgdudeggduejdehxexdedueue
原创粉丝点击