"李江1" <[email protected]>,"李江2" <[email protected]>,"李江3" <[email protected]>,"李江4" <[email protected]>,"李江1" <[email protected]>,"李江2" <[email protected]>,"李江3" <[email protected]>,"李江4" <[email protected]>,"李江1" <[email protected]>,"李江2" <[email protected]>,"李江3" <[email protected]>,"李江4" <[email protected]>
在文本框输入这么多的内容,,,怎么用javascript,,,,和java这两种语言,,,,,的正则表达式进行验证

解决方案 »

  1.   

    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.regex.*;//正则表达式获取网页上的邮箱地址
    public class MyRegex {
    public static void main(String[] args) {

    try {
    //读取网页文件,里面有N个邮箱地址
    String content = read("e:/1.htm");//read()方法在下面
    //匹配邮箱的正则表达式
    String regex="\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
    Matcher m=Pattern.compile(regex).matcher(content);
    while(m.find()){
    //输出邮箱地址
    System.out.println(m.group());
    }
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

    /**
     * 读取文本内容
     * @param fileName 文本名称,包括路径
     * @return 返回文本内容
     */
    public static String read(String fileName) throws IOException{
    BufferedReader br=new BufferedReader(new FileReader(fileName));
    StringBuilder sb=new StringBuilder();
    String s;
    while((s=br.readLine())!=null)
    {
    sb.append(s);
    sb.append("\r\n");
    }
    br.close();
    return sb.toString();
    }
    }
      

  2.   

    告诉你呀,你可以用String.Substring()进行操作呀,这样的话,就是用两个for()就可以搞定啦,具体怎么用去找一下API啦
      

  3.   

    为写的都是什么呀,,,一个谁不会验证呀,,,,我要的是一串呀,,,
    Pattern p1=Pattern.compile("\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");Matcher m1=p1.matcher("\"李江1\" <[email protected]>,\"李江2\" <[email protected]>,\"李江3\" <[email protected]>");
    System.out.println(m1.matches());//为什么是false这是合法的呀,,,,
    还是没明白我说的什么意思呀,哈哈,,,真有点想不明白,,,,我这个问题怎么解决,,,哈哈,,,
    有人会吗,哈哈,,,来给说一下,,,,我在这里说声谢谢了,
      

  4.   

    你先用String.split()的来截取成Str[0]="李江1" <[email protected]> 然后在用String的一个方法获得<>中的字符串在用正则表达式判断就好了一个for循环就能验证了
      

  5.   

    import java.util.regex.*;public class MyRegex
    {
    public static void main(String[] args)
    {
    String content = "\"李江1\" <[email protected]>,\"李江2\" <[email protected]>," +
    "\"李江3\" <[email protected]>,\"李江4\" <[email protected]>," +
    "\"李江1\" <[email protected]>,\"李江2\" <[email protected]>," +
    "\"李江3\" <[email protected]>,\"李江4\" <[email protected]>," +
    "\"李江1\" <[email protected]>,\"李江2\" <[email protected]>," +
    "\"李江3\" <[email protected]>,\"李江4\" <[email protected]> ";
    // 匹配邮箱的正则表达式
    String regex = "\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
    Matcher m = Pattern.compile(regex).matcher(content);
    while (m.find())
    {
    // 输出邮箱地址
    System.out.println(m.group());
    }
    }
    }
      

  6.   

    javascript中调用这个函数就可以验证了。
    function isEmail(str){
           var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
           return reg.test(str);
    }
      

  7.   

    大哥哪,不能截取呀,,我这是做一个邮件发送系统,,,,要是截取了之后就看不见那个友好短名字提示了,,,,要是还是不明白我说的意思的话,,,那就请各们大哥,,上163邮箱,,,发一下信,,,看一下,,,给多个人发信是不是这个样子,,的,,,,还有兴趣的话,,也看一下javamail,,,谢谢各位大哥的回答,,,,
      

  8.   

    如果只是邮箱,这个表达式可以:\\w+(\\.\\w+)*@\\w+(\\.\\w+)+它可以匹配如下的几种邮件格式:[email protected]
    [email protected]
    [email protected]
    [email protected]
      

  9.   

    那就写成[,]*\"[^\\s,]+?\"<\\w+(\\.\\w+)*@\\w+(\\.\\w+)+>,?说明:
    1、收信人的名字不能为空,也不能为空格;
    2、如果出现了违反1的情况,则其后续的匹配中会在符合条件的字符串前多一个逗号,这是表达式匹配所产生的,处理时可以去掉。只是简单测试了一下,没有仔细测试。
      

  10.   


      String reg1 = "(\"[^\"]+\" *(<([\\w]+)(.[\\w]+)*@([\\w-]+\\.){1,5}([A-Za-z]){2,4}>),)*(\"[^\"]+\" *(<([\\w]+)(.[\\w]+)*@([\\w-]+\\.){1,5}([A-Za-z]){2,4}>))";
      String text = "\"姓名\"<[email protected]>,\"姓名\"<[email protected]>,\"姓名\"<[email protected]>,\"姓名\"<[email protected]>";
     String text1 = "\"姓名\"<[email protected]>,";
     String text2 = "\"姓名\"<aaaayahoo.cn>,\"姓名\"<[email protected]>";
     String text3 = "\"<aaaayahoo.cn>,\"姓名\"<[email protected]>";
      Pattern pp = Pattern.compile(reg1);
      System.out.println(pp.matcher(text).matches());
      System.out.println(pp.matcher(text1).matches());
      System.out.println(pp.matcher(text2).matches());
      System.out.println(pp.matcher(text3).matches());