Java 中的 boolean matches(String reg

首页 / Java入门教程 / Java 中的 boolean matches(String reg

此字符串是否与给定的正则表达式匹配,以str.matches(regex)形式调用此方法所产生的输出与表达式Pattern.matches(regex,str)完全相同。

 boolean matches - 语法

这是此方法的语法-

public boolean matches(String regex)

这是参数的详细信息-

  • regex   -  此字符串要匹配的正则表达式。

boolean matches - 返回值

boolean matches - 示例

import java.io.*;
public class Test {

   public static void main(String args[]) {
      String Str=new String("Welcome to Learnfk.com");

      System.out.print("返回值 :" );
      System.out.println(Str.matches("(.*)Learnfk(.*)"));

      System.out.print("返回值 :" );
      System.out.println(Str.matches("LearnFk"));

      System.out.print("返回值 :" );
      System.out.println(Str.matches("Welcome(.*)"));
   }
}

这将产生以下输出-

返回值 :true
返回值 :false
返回值 :true

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

深入浅出gRPC -〔李林锋〕

Nginx核心知识150讲 -〔陶辉〕

Vue开发实战 -〔唐金州〕

玩转webpack -〔程柳锋〕

雷蓓蓓的项目管理实战课 -〔雷蓓蓓〕

Service Mesh实战 -〔马若飞〕

爱上跑步 -〔钱亮〕

手把手带你写一门编程语言 -〔宫文学〕

Rust 语言从入门到实战 -〔唐刚〕

好记忆不如烂笔头。留下您的足迹吧 :)