集册 Java实例教程 匹配词以正则表达式开头

匹配词以正则表达式开头

欢马劈雪     最近更新时间:2020-01-02 10:19:05

409
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
匹配词以正则表达式开头

import java.util.regex.Pattern;

import java.util.regex.Matcher;
/*
来 自*
 N o w J a v a . c o m - 时  代  Java
*/


public class MatchesLooking {


    private static final String REGEX = "foo";

    private static final String INPUT = "fooooooooooooooooo";

    private static Pattern pattern;

    private static Matcher matcher;


    public static void main(String[] args) {


        // Initialize

        pattern = Pattern.compile(REGEX);

        matcher = pattern.matcher(INPUT);


        System.out.println("Current REGEX is: " + REGEX);

        System.out.println("Current INPUT is: " + INPUT);


        System.out.println("lookingAt(): " + matcher.lookingAt());/*时   代    Java - nowjava.com 提 供*/

        System.out.println("matches(): " + matcher.matches());

    }

}


展开阅读全文