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

用正则表达式匹配字符串

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

552
用正则表达式匹配字符串
/* 来自 时代Java - N o w  J a v a . c o m*/

import java.util.regex.Matcher;

import java.util.regex.Pattern;


public class Main {

  private String jaText = "this is a test ";



  public Main() {

    Pattern p = Pattern.compile(".at");

    Matcher m = p.matcher(jaText);

    while (m.find()) {

      System.out.printf("%s\n", m.group());

    }

  }

}