查看中文原版 English Version

Java API频道主页 > java.util.regex > Pattern > public static boolean matches(String regex, CharSequence input)

搜索标题关键字:


matches
public static boolean matches(String regex,

CharSequence input)
编译给定正则表达式并尝试将给定输入与其匹配。

调用此便捷方法的形式

Pattern.matches(regex, input);
与表达式
Pattern.compile(regex).matcher(input).matches() 
的行为完全相同。

如果要多次使用一种模式,编译一次后重用此模式比每次都调用此方法效率更高。

参数:
regex - 要编译的表达式
input - 要匹配的字符序列
抛出:
PatternSyntaxException - 如果表达式的语法无效