类似这样的字符串: “(陈好)[email protected],(李梦瑶)[email protected],(焦斌斌)[email protected],”
我想得到的结果是:“[email protected],[email protected],[email protected]”,也就是去掉所有小括号,姓名和最后一个逗号,用java处理,比较急,请高手帮忙呀,在线急等
我想得到的结果是:“[email protected],[email protected],[email protected]”,也就是去掉所有小括号,姓名和最后一个逗号,用java处理,比较急,请高手帮忙呀,在线急等
检测到'@'则删除直到',';首先定义一个flag=true时
则将检测到符号删除
flag=false则保存字母检测到'('将flag设为true;无论检测到什么都删除直到')'将flag=false;
检测到'('将flag设为true;无论检测到什么都删除直到','将flag=true;
当flag=true时就把检测到的字符串删除
String s = "(陈好)[email protected],(李梦瑶)[email protected],(焦斌斌)[email protected],";
// 去掉括号
s = s.replaceAll("\\(.+?\\)", "");
// 去掉最后一个逗号
s = s.substring(0, s.lastIndexOf(","));
System.out.println(s);
}// [email protected],[email protected],[email protected]
"\\(.+?\\)" ??????????
哦,我也写了一个。呵呵。
String str="(陈好)[email protected],(李梦瑶)[email protected],(焦斌斌)[email protected],";
System.out.println(str.replaceAll("\\(.+?\\)|,(?=$)", ""));
//[email protected],[email protected],[email protected]
public static void main(String[] args) {
String s = "(陈好)[email protected],(李梦瑶)[email protected],(焦斌斌)[email protected],"; s = s.replaceAll("\\([^\\)]*\\)", ""); s = s.substring(0, s.length() - 1); System.out.println(s); }
故
String str = "(陈好)[email protected],(李梦瑶)[email protected],(焦斌斌)[email protected],";
str = str.replaceAll("\\([\\u4e00-\\u9fa5]*\\)", "");
System.out.println(str);
if(str.lastIndexOf(",")==str.length()-1){//如果结尾保证不是,号这个substring处理可以不要
str = str.substring(0,str.length()-1);
}
String[] emails = str.split(",?(\\(.*?\\))");//emails得到
for(int i=0;i<emails.length;i++){
System.out.println(emails[i]);
}
String emailStr = "(陈娟)[email protected],(陈瑶)[email protected],(崔斌斌)[email protected]";
emailStr = emailStr.replaceAll("[^0-9a-zA-Z@.,]{1,}", "");
System.out.println(emailStr);
//我是来拿分的,O(∩_∩)O哈哈~