TestRegex

package com.njwb18081.day13;

public class TestRegex {
    /**
     * @param args
     */
    /**
     * @param args
     */
    public static void main(String[] args) {
        String str="aabbccddeeff";
        boolean b=str.matches("aabbccddeeff");//matches(String/regex格式)
        System.out.println(b);

        String regex="[abcdef]";//只包含a,b,c,d,e,f单个字符的正则
        System.out.println("z".matches(regex));//false
        System.out.println("f".matches(regex));//true




//      除了abc字符的正则
        System.out.println("f".matches("[^abc]"));//true
        System.out.println("a".matches("[^abc]"));//false


//      大写A~D G~Z的正则
        System.out.println("E".matches("[A-D[G-Z]]"));//false
        System.out.println("H".matches("[A-D[G-Z]]"));//true






//      数字出现0次或一次
        System.out.println("66".matches("[0-9]?"));//false
//      数字出现0次或多次
        System.out.println("66".matches("[0-9]*"));//true
//      大写A~Z英文字符最少4个最多6个
        System.out.println("AAAAAAA".matches("[A-Z]{4,6}"));

//      java中针对于字符串反斜杠\通过\做转移
//      数字恰好是5次后跟小写英文字母恰好是5次
        System.out.println("12321adsad".matches("(\\d){5}([a-z]{5})"));

//      QQ号 6位~11位 \d{6,11}
        System.out.println("1234567890".matches("\\d{6,11}"));

//      QQ邮箱 数字6~11位@qq.com
        System.out.println("1234567890@qq.com".matches("\\d{6,11}@qq.com"));

//      邮箱格式    数字6~11位@qq或sina.com或cn \\d{6,11}@(qq|sina).(com|cn)
//      1234567890@qq.com
//      1234567890@sina.com
//      1234567890@qq.cn
//      1234567890@sina.cn
        System.out.println("1234567890@sina.cn".matches("\\d{6,11}@(qq|sina).(com|cn)"));

//      电话号码    3~4位的数字-8位数字   \\d{3,4}-\d{8}
        System.out.println("0536-12345678".matches("\\d{3,4}-\\d{8}"));

//      密码 首字母大写后跟8~11位英文或数字@qq或sina.com或cn
//      [A-Z]{1}(\\d|[a-zA-Z]) {8,11}@(qq|sina).(com|cn)
        System.out.println("LaaaAAA11134@sina.com".matches("[A-Z]{1}(\\d|[a-zA-Z]){8,11}@(qq|sina).(com|cn)"));

        String str2="sadsa12321sadsad213213sadsad32132";
        System.out.println(str2.replaceAll("\\d{5,6}", "HELLO"));

        str2="13955663344,13955664544,13955668844,13955665644";
        System.out.println(str2.replaceAll("(\\d{3})(\\d{4})(\\d{4})", "$1****$3"));



    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值