类似这样的字符串: “(陈好)[email protected],(李梦瑶)[email protected],(焦斌斌)[email protected],”
我想得到的结果是:“[email protected],[email protected],[email protected]”,也就是去掉所有小括号,姓名和最后一个逗号,用java处理,比较急,请高手帮忙呀,在线急等

解决方案 »

  1.   

    检测到'('则删除字母直到')'
    检测到'@'则删除直到',';首先定义一个flag=true时
    则将检测到符号删除
    flag=false则保存字母检测到'('将flag设为true;无论检测到什么都删除直到')'将flag=false;
    检测到'('将flag设为true;无论检测到什么都删除直到','将flag=true;
    当flag=true时就把检测到的字符串删除
      

  2.   

    public static void main(String[] args) {
    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]
      

  3.   

    thc1987写的方法真的很酷,能不能解释一下这个正则表达式的含义
    "\\(.+?\\)"   ??????????
      

  4.   


    哦,我也写了一个。呵呵。
    String str="(陈好)[email protected],(李梦瑶)[email protected],(焦斌斌)[email protected],";
    System.out.println(str.replaceAll("\\(.+?\\)|,(?=$)", ""));
    //[email protected],[email protected],[email protected]
      

  5.   


    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); }
      

  6.   

    正则 \([\u4e00-\u9fa5]*\) 匹配(任意汉字)

    String str = "(陈好)[email protected],(李梦瑶)[email protected],(焦斌斌)[email protected],";
    str = str.replaceAll("\\([\\u4e00-\\u9fa5]*\\)", "");
    System.out.println(str);
      

  7.   

    可以简化一下:str.replaceAll("\\(.+?\\)|,$", "")
      

  8.   

    三楼的方法很好,很简单,呵呵。使用replace直接将指定字符串替换~~我还在想怎么用坐标计算呢~~~我土了~~~
      

  9.   

    split也有类似效果        String str ="(陈好)[email protected],(李梦瑶)[email protected],(焦斌斌)[email protected],";
            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]);
            }
      

  10.   


    String emailStr = "(陈娟)[email protected],(陈瑶)[email protected],(崔斌斌)[email protected]";
    emailStr = emailStr.replaceAll("[^0-9a-zA-Z@.,]{1,}", "");
    System.out.println(emailStr);
    //我是来拿分的,O(∩_∩)O哈哈~