首页 > 编程知识 正文

java基础语法代码示例,php常用代码及用法

时间:2023-05-06 00:22:16 阅读:251020 作者:2344

匹配器类的matches()方法用于获取结果,无论此模式是否与此匹配器匹配。它返回一个显示相同值的布尔值。

用法:

public boolean matches()

参数:此方法不带任何参数。

返回值:此方法返回一个布尔值,该值显示此模式是否与此匹配器匹配。

下面的示例说明Matcher.matches()方法:

示例1:

// Java code to illustrate matches() method

import java.util.regex.*;

public class GFG {

public static void main(String[] args)

{

// Get the regex to be checked

String regex = "Geeks";

// Create a pattern from regex

Pattern pattern

= Pattern.compile(regex);

// Get the String to be matched

String stringToBeMatched

= "GeeksForGeeks";

// Create a matcher for the input String

Matcher matcher

= pattern

.matcher(stringToBeMatched);

// Get the result state

// using matches() method

System.out.println("Result: "

+ matcher.matches());

}

}

输出:

Result: false

示例2:

// Java code to illustrate matches() method

import java.util.regex.*;

public class GFG {

public static void main(String[] args)

{

// Get the regex to be checked

String regex = "GFG";

// Create a pattern from regex

Pattern pattern

= Pattern.compile(regex);

// Get the String to be matched

String stringToBeMatched

= "GFGFGFGFGFGFGFGFGFG";

// Create a matcher for the input String

Matcher matcher

= pattern

.matcher(stringToBeMatched);

// Get the result state

// using matches() method

System.out.println("Result: "

+ matcher.matches());

}

}

输出:

Result: false

win7电脑文件夹如何加密

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。