集册 Java实例教程 字符串与正则表达式匹配

字符串与正则表达式匹配

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

493
字符串与正则表达式匹配

public class Main {

  private String jaText = "this is a test ";

  private String enText = "The fat cat sat on the mat with a brown rat.";

  private String enRegEx = "^The \\w+ cat.*";//n o w j a   v  a . c o m - 时  代  Java

  private String jaRegEx = ".*.*";

  private String jaRegExEscaped = ".*\u6587\u5B57.*";


  public Main() {


    boolean found = false;

    found = enText.matches(enRegEx);

    if (found) {

      System.out.printf("Matches %s.\n", enRegEx);

    }


    found = jaText.matches(jaRegEx);

    if (found) {

      System.out.printf("Matches %s.\n", jaRegEx);

    }


    found = ja
展开阅读全文