正则表达式(一)

public class RegexDemo {
/**
 * 对qq号码进行校验
 * 要求:5-15,0不能开头只能是数字
 */

public static void main(String[] args) {
String qq="360468490";
String regex="[1-9][0-9]{4,14}";//第一位后面的只能是0-9的数字,且后面可以存在的数字必须是4-14个
boolean flag=qq.matches(regex);
if(flag){
System.out.println("匹配");
}else{
System.out.println("不匹配");
}
}



}


//*************************************



public static void main(String[] args) {
String str="b9";
String regex="[a-zA-Z]\\d?";//  \d第二位是数字,?表示可能不出现,或出现一次
boolean flag=str.matches(regex);
if(flag){
System.out.println("匹配");
}else{
System.out.println("不匹配");
}
}
//*********************************************************

public static void main(String[] args) {
String str="tyddhfjjlkmbbkr";
String regex="(.)\\1";
String[] strs=str.split(regex);
for(String s:strs){
System.out.println(s);
}
}

ty
hf
lkm
kr

//********************************************

public static void main(String[] args) {
String str="tyddhfjjlkmbbbbkr";
String regex="(.)\\1+";//+一次或多次
String[] strs=str.split(regex);
for(String s:strs){
System.out.println(s);
}
}

ty
hf
lkm
kr


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ygl6150373

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值