viway
viway
2008-11-14 10:42
浏览 563
已采纳

求一个去括号()中间任意字符串的JAVA正则表达式

String s="(Jack)jack1@163.com,"+

          "(杰克)jack2@qq.com,"+

          "(jack son.杰克)jack3@qq.com,"+

          "(杰克.jack)jack4@qq.com,";



String result= s.replaceAll('正则表达式','');

// result = "jack1@163.com,jack2@qq.com,jack3@qq.com,jack4@qq.com





求一个正则表达式去掉邮件地址前面的姓名信息()内的,这些信息是任意的字符串,有可能是中文,英文,中英文混合,空白符等;

先谢谢了
问题补充:
String s="(Jack)jack1@163.com,"+


????????? "(杰克)jack2@qq.com,"+


????????? "(jack son.杰克)jack3@qq.com,"+


????????? "(杰克(先生).jack)jack4@qq.com,";





String result= s.replaceAll('正则表达式','');


// result = "jack1@163.com,jack2@qq.com,jack3@qq.com,jack4@qq.com








求一个正则表达式去掉邮件地址前面的姓名信息()内的,这些信息是任意的字符串,有可能是中文,英文,中英文混合,空白符等;


先谢谢了



谢谢二楼的热情解答,你的回答已经解决了我的问题,但如果邮件地址前面()里的姓名信息也有括号如:(杰克(先生).jack)jack4@qq.com,这个正则又该怎么也写呢?


问题补充:
String s="(Jack)jack1@163.com,"+


????????? "(杰克)jack2@qq.com,"+


????????? "(jack son.杰克)jack3@qq.com,"+


????????? "(杰克.jack)jack4@qq.com,";





String result= s.replaceAll('正则表达式','');


// result = "jack1@163.com,jack2@qq.com,jack3@qq.com,jack4@qq.com
谢谢二楼的热情解答,你的回答已经解决了我的问题,但如果邮件地址前面()里的姓名信息也有括号如:(杰克(先生).jack)jack4@qq.com,这个正则又该怎么也写呢?



问题补充:

String s="(Jack)jack1@163.com,"+ 
"(杰克)jack2@qq.com,"+
"(jack son.杰克)jack3@qq.com,"+
"(杰克(先生).jack)jack4@qq.com,"+
"()jack4@qq.com,";




这个是最全的情况了..

s.replaceAll("\([^)]+\)","");

可以解决前面三个,后面两个还是不对.
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • bohemia
    bohemia 2008-11-14 13:12
    已采纳

    [code="java"]String s="(Jack)jack1@163.com,"+
    "(杰克)jack2@qq.com,"+
    "(jack son.()杰克)jack3@qq.com,"+
    "(杰克.jack)jack4@qq.com,";

    String result= s.replaceAll("\((?<=\()[^@]+(?=(\)[^)]+@))\)","");
    System.out.println("Result:"+result);[/code]

    给你个连接,有空看看吧.

    http://unibetter.com/deerchao/zhengzhe-biaodashi-jiaocheng-se.htm

    点赞 评论
  • bohemia
    bohemia 2008-11-14 11:20

    又是正则...
    看看这个,应该可以达到你的目的;

    [code="java"]String s="(Jack)jack1@163.com,"+
    "(杰克)jack2@qq.com,"+
    "(jack son.杰克)jack3@qq.com,"+
    "(杰克.jack)jack4@qq.com,";

    String result= s.replaceAll("\([^)]+\)","");

    System.out.println("Result:"+result);[/code]

    点赞 评论

相关推荐