集册 Java实例教程 使用正则表达式模式完全匹配字符串文字

使用正则表达式模式完全匹配字符串文字

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

435
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用正则表达式模式完全匹配字符串文字

import java.util.regex.Matcher;

import java.util.regex.Pattern;
/*来自 N o w  J a v a  .   c o m*/

public class Main {

  public static void main(String[] args) {

    Pattern pattern = Pattern.compile("abc");

    Matcher matcher = pattern.matcher("abc");

    if (matcher.matches())

      System.out.println("Match.");

    else

      System.out.println("Does not match.");

  }


}