package com.test; /** * 如何使用正则表达式验证QQ号(假如QQ号是5-10,不能以0开头,且只能是数字) * @author Administrator * */ public class RegexDemo { public static void main(String[] args){ checkQQ(); } public static void checkQQ(){ String QQ="012345"; String regex="[1-9]\\d{4,14}"; boolean flag= QQ.matches(regex); if(flag){ System.out.println("是QQ号"); }else{ System.out.println("不是QQ号"); } } }原文链接:https://www.f2er.com/regex/361598.html