Java_Regex

public class Test {

    public static void main(String[] args) {
      //  System.out.println("abc".matches("..."));
       /* Pattern p = Pattern.compile("[a-z]{3}");
        Matcher m = p.matcher("sfg");
        System.out.println(m.matches());
        System.out.println("\\");*/
        /*System.out.println("\\".matches("\\\\"));
        System.out.println(" \n\r\t".matches("\\s{4}"));
        System.out.println(" ".matches("\\S"));.0
        System.out.println("a_6".matches("\\w{3}"));
        System.out.println("abc888&^%".matches("[a-z]+\\d+[&^%]+"));*/


        //匹配汉字
        /*System.out.println("孙悟空".matches("^[\\u4e00-\\u9fa5]{0,}$"));


        //white lines
        System.out.println(" \n".matches("^[\\s&&[^\\n]]*\\n$"));*/


        //匹配email地址1125334959@qq.com   menglingshaui@outlook.com  menglingshaui@163.com
        /*String email = "[\\w-]+@[\\w[-.]]+\\.[\\w]+";
        String s = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
        String m = ".";
        p("kefu@youkuaiyun.com".matches(email));*/


        //matches find lookingAt
       /* Pattern p = Pattern.compile("\\d{3,5}");
        String s ="123-45678-654-00";
        Matcher m = p.matcher(s);*/
        //p(m.matches());
        //m.reset();
        /*p(m.find());
        p(m.start() + "-" + m.end());
        p(m.find());
        p(m.start() + "-" + m.end());*/
        //p(m.lookingAt());
        //p(m.lookingAt());


       /* Pattern p = Pattern.compile("java",Pattern.CASE_INSENSITIVE);
        Matcher m = p.matcher("java Java JAVa JaVa IloveJAVA you hateJava");
        StringBuffer buf = new StringBuffer();
        p(buf);
        int index = 0;
        while(m.find()) {
           // p(m.group());
            index ++;
            if(index %2 == 0) {
                m.appendReplacement(buf,"JAVA");
            } else {
                m.appendReplacement(buf,"java");
            }
        }
        p(buf);*/


       //group
       /* Pattern p = Pattern.compile("(\\d{3,5})([a-z]{2})");
        String s = "123aa-34345bb-234cc-0002cc";
        Matcher m = p.matcher(s);
        while(m.find()) {
            p(m.group());
        }*/



       //non-capturing groups
        Pattern p = null;
        //p = Pattern.compile(".{3}(?=a)");
        //p = Pattern.compile(".{3}(?!a)");
        //p = Pattern.compile("(?=a).{3}");
       /* p = Pattern.compile("(?!a).{3}");
        Matcher m = p.matcher("444a55j");
        while(m.find()) {
            p(m.group());
        }*/


        //back refenrences
      /* p = Pattern.compile("(\\d(\\d))\\1");
       Matcher m = p.matcher("1212");
       System.out.println(m.find());*/

      //flags 的简写
       // p = Pattern.compile("java",Pattern.CASE_INSENSITIVE);
        p = Pattern.compile("(?i)(java)");
        Matcher m = p.matcher("JAVA java");
        while(m.find()) {
            p(m.group());
        }
    }

    public static void p(Object o) {
        System.out.println(o);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值