集册 Java实例教程 如果字符串通过正则表达式精确包含“单词”,则返回true

如果字符串通过正则表达式精确包含“单词”,则返回true

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

394
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
如果字符串通过正则表达式精确包含“单词”,则返回true

/** 
来 自 
nowjava.com - 时代Java
**/

public class Main {

  public static void main(String args[]) {


    String s = "main";

    s = s.toLowerCase();

    if (s.matches(".*main.*")) // returns true if the string contains exactly "main"

      System.out.println("found");

  }

}