java正则使用

2018-03-02  本文已影响4人  Vijay_
String regex = "正则";
Pattern pattern = Pattern.complie(regex);
String[] strArr = pattern.split("需要正则切割的字符串");

String regex = "正则";
Pattern pattern = Pattern.complie(regex);
Matcher matcher = pattern.matcher("需要处理的字符串");
matcher.find();//返回布尔值 表示是否能捕获到
log(matcher.group(0));
log(matcher.group(1));
...

       Pattern pattern = Pattern.compile(".{3}abc.{3}");
        Matcher matcher = pattern.matcher("asdabcasd");
        boolean b = matcher.matches();
        System.out.println(b);//true
上一篇下一篇

猜你喜欢

热点阅读