25,980
社区成员
发帖
与我相关
我的任务
分享
package testsplit;
public class testsplit {
public static void main(String[] args){
String str = "this^is^my^girl^^^^friend!";
//第一个括号表示前面一个字符不能是^,中间匹配^,最后表示后面不能为^,注意:^是正则表达式关键字,所以要转义
String reg = "(?<!\\^)(\\^)(?!\\^)";
String[] s = str.split(reg);
String result = "";
for(int i=0;i<s.length;i++){
result += s[i] + " ";
}
System.out.println(result);
}
}