黑马程序员技术交流社区
标题:
JAVA正则_验证邮箱_重复组调用问题
[打印本页]
作者:
未烧开的白开水
时间:
2014-2-27 16:47
标题:
JAVA正则_验证邮箱_重复组调用问题
正则:^[a-zA-Z][\\w_]*@\\w+(\\.[a-zA-Z]+)+$
有两块相同的验证:[a-zA-Z],
我使用组的概念改写为:^([a-zA-Z])[\\w_]*@\\w+(\\.\\1+)+$
就会验证失败,为什么?
我的代码:
package com.test.basic.regularexpression;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Pattern;
/**
* 简单测试
* @author yanan.wang
* 2014.2.24
*
*/
public class SimpleRegExpTest {
public static void main(String[] args) {
/*
* 验证邮箱格式-略精确验证
*/
simpleRegExpTest("^([a-zA-Z])[\\w_]*@\\w+(\\.[a-zA-Z]+)+$");
}
public static void simpleRegExpTest(String regex) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while(true) {
try {
String input = br.readLine();
if(input.equals("exit")) {
br.close();
System.exit(0);
}
System.out.println(input + ", " + Pattern.matches(regex, input));
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
复制代码
作者:
asvsass
时间:
2014-2-27 20:17
应该是组里不能再调用其他组吧
作者:
未烧开的白开水
时间:
2014-2-27 20:58
asvsass 发表于 2014-2-27 20:17
应该是组里不能再调用其他组吧
能确定吗,详细说一下呗~~
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2