zoukankan      html  css  js  c++  java
  • Regex 正则表达式的练习

    package com.company.danei;
    
    import java.util.Scanner;
    
    /**
     * @Author: 
     * @Date: 2021-05-09
     * @Description: 通过正则表达式校验身份证号码是否正确
     * 1、接收用户输入的一行字符串
     * 2、定义正则表达式
     * 3、通过matches方法比较输入的字符串是否符合正则表达式
     **/
    public class Test_Regex {
        public static void main(String[] args) {
            //定义正则表达式
            String regex = "[0-9]{17}[0-9X]";
            boolean b=true;
            do {
                //接收用户输入的一行字符串
                System.out.println("please input the number");
                String str = new Scanner(System.in).nextLine();
                //通过matches方法比较输入的字符串是否符合正则表达式
               if(str.matches(regex)) {
                   System.out.println("ok");
                   break;
               };
            }while (b);
        }
    }
  • 相关阅读:
    使用正则表达式实现(加减乘除)计算器(C#实现)
    asp.net core中间件工作原理
    WPF
    WPF
    WPF
    WPF
    WPF 3D Cube及点击交互
    WPF 3D足球导览
    WPF 3D 球面导览
    WPF 3D球及进阶玩法
  • 原文地址:https://www.cnblogs.com/xiaohai2003ly/p/14749262.html
Copyright © 2011-2022 走看看