正则表达式简单应用1

/*
*
* 分析:
* A:键盘录入邮箱
* B:定义邮箱的规则
* 14851806580@qq.com
* lidyid@163.com
* linqingxia@126.com
* fengqingyang@sina.com.cn
* fqy@itcast.cn
* C:调用功能,判断即可
* D:输出结果
*/

import java.util.Scanner;

//校验邮箱
public class MatchTest {
    public static void main(String[] args) {
        //校验QQ邮箱
        /*System.out.println("请输入你的邮箱号");
        Scanner scan = new Scanner(System.in);
        String qq = scan.nextLine();
        String regex = "[1-9][0-9]{4,14}@qq\\.com";
        System.out.println(qq.matches(regex));
        scan.close();*/
        System.out.println("请输入你的邮箱号");
        Scanner scan = new Scanner(System.in);
        String qq = scan.nextLine();
        String regex = 
                "[a-zA-Z_0-9]+@[a-zA-Z_0-9]{2,6}(\\.[a-z_A-Z0-9]{2,3})+";
        //regex ="\\w+@\\w{2,6}(\\.\\w{2,3})+"
        System.out.println(qq.matches(regex));
        scan.close();
    }
}
posted @ 2016-11-14 19:08  第五个世界  阅读(100)  评论(0编辑  收藏  举报