1import java.util.Scanner; 2 3public class RegexDemo { 4 public static void main(String[] args) { 5 // 创建键盘录入对象 6 Scanner sc = new Scanner(System.in); 7 System.out.println("请输入你的QQ号码:"); 8 String qq = sc.nextLine(); 9 System.out.println("checkQQ:" + checkQQ(qq)); 10 sc.close(); 11 } 12 13 public static boolean checkQQ(String qq) { 14 // String regex ="[1-9][0-9]{4,14}"; 15 // public boolean matches(String regex)告知此字符串是否匹配给定的正则表达式 16 // boolean flag = qq.matches(regex); 17 // return flag; 18 19 //return qq.matches("[1-9][0-9]{4,14}"); 20 return qq.matches("[1-9]\\d{4,14}"); 21 } 22}
5.48 正则表达式的概述和基本使用
Wesley13
2021-10-11
1334 0 0
点赞
收藏
评论区
加载中...