加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式--find lookingAt

发布时间:2020-12-14 04:23:37 所属栏目:百科 来源:网络整理
导读:import java.util.regex.Matcher; import java.util.regex.Pattern; public class MainClass { public static void main (String arg[]) { String string= "123-34345-234-00" ; Pattern pattern = Pattern.compile( "d{3,5}" ); Matcher matcher = patter
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class MainClass {

    public static void main(String arg[]) {

        String string="123-34345-234-00";

        Pattern pattern = Pattern.compile("d{3,5}");
        Matcher matcher = pattern.matcher(string);

        boolean result1= matcher.matches();
        System.out.println("result1="+result1);

        //重置匹配器。
        matcher.reset();

        //尝试查找与该模式匹配的输入序列的下一个子序列。
        boolean result2 = matcher.find();
        System.out.println("result2="+result2);
        boolean result3 = matcher.find();
        System.out.println("result3="+result3);
        boolean result4 = matcher.find();
        System.out.println("result4="+result4);
        boolean result5 = matcher.find();
        System.out.println("result5="+result5);

        //尝试将从区域开头开始的输入序列与该模式匹配。
        boolean result6 = matcher.lookingAt();
        System.out.println("result6="+result6);
        boolean result7 = matcher.lookingAt();
        System.out.println("result7="+result7);
        boolean result8 = matcher.lookingAt();
        System.out.println("result8="+result8);
    }
}
result1=false
result2=true
result3=true
result4=true
result5=false
result6=true
result7=true
result8=true

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读