集册 Java实例教程 使用正则表达式查找匹配项

使用正则表达式查找匹配项

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

605
使用正则表达式查找匹配项
/**
 from
* nowjava 
**/

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("japanese letter");

    Matcher m = p.matcher(jaText);

    if (m.find()) {

      System.out.println(m.group());

    }
    /*
     from N o w  J a v a  .   c o m 
    */

  }

}