0
0

More than 1 year has passed since last update.

regular expressionによるmatching

Posted at

find()は部分一致検索
lookingAtは先頭一致
matchesは完全一致

        String s = "ABC1DEF";
        Pattern p = Pattern.compile("[A-Z]{3}");
        Matcher mc = p.matcher(s);
        System.out.println(mc.find());
        System.out.println(mc.group());
        System.out.println(mc.find());
        System.out.println(mc.group());
        System.out.println(mc.find());
        System.out.println("-----------------");
        System.out.println(mc.lookingAt());
        System.out.println(mc.group());
        System.out.println(mc.lookingAt());
        System.out.println(mc.group());
        System.out.println("-----------------");
        System.out.println(mc.matches());
        mc = p.matcher("ABC");
        System.out.println(mc.matches());
true
ABC
true
DEF
false
-----------------
true
ABC
true
ABC
-----------------
false
true
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0