黑马程序员技术交流社区

标题: JAVA正则_验证邮箱_重复组调用问题 [打印本页]

作者: 未烧开的白开水    时间: 2014-2-27 16:47
标题: JAVA正则_验证邮箱_重复组调用问题
正则:^[a-zA-Z][\\w_]*@\\w+(\\.[a-zA-Z]+)+$

有两块相同的验证:[a-zA-Z],
我使用组的概念改写为:^([a-zA-Z])[\\w_]*@\\w+(\\.\\1+)+$
就会验证失败,为什么?

我的代码:
  1. package com.test.basic.regularexpression;

  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. import java.util.regex.Pattern;

  6. /**
  7. * 简单测试
  8. * @author yanan.wang
  9. * 2014.2.24
  10. *
  11. */
  12. public class SimpleRegExpTest {
  13.        
  14.         public static void main(String[] args) {
  15.                
  16. /*
  17.                  * 验证邮箱格式-略精确验证
  18.                  */
  19.                 simpleRegExpTest("^([a-zA-Z])[\\w_]*@\\w+(\\.[a-zA-Z]+)+$");
  20.         }

  21.         public static void simpleRegExpTest(String regex) {
  22.                
  23.                 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  24.                 while(true) {
  25.                         try {
  26.                                 String input = br.readLine();
  27.                                 if(input.equals("exit")) {
  28.                                         br.close();
  29.                                         System.exit(0);
  30.                                 }
  31.                                 System.out.println(input + ", " + Pattern.matches(regex, input));
  32.                         } catch (IOException e) {
  33.                                 e.printStackTrace();
  34.                         }
  35.                 }
  36.         }
  37. }
复制代码




作者: asvsass    时间: 2014-2-27 20:17
应该是组里不能再调用其他组吧
作者: 未烧开的白开水    时间: 2014-2-27 20:58
asvsass 发表于 2014-2-27 20:17
应该是组里不能再调用其他组吧

能确定吗,详细说一下呗~~




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2