它輸出字符串是否與給定的正則表達式匹配。
用法
Boolean matches(String regex)
參數
Regex─ 用於比較的表達式。
返回值
當且僅當此字符串與給定的正則表達式匹配時,此方法才返回 true。
以下是該方法的使用示例
class Example {
static void main(String[] args) {
String a = "Hello World";
println(a.matches("Hello"));
println(a.matches("Hello(.*)"));
}
}
當我們運行上麵的程序時,我們會得到以下結果——
false true
相關用法
- Groovy max()用法及代碼示例
- Groovy min()用法及代碼示例
- Groovy after()用法及代碼示例
- Groovy padRight()用法及代碼示例
- Groovy contains()用法及代碼示例
- Groovy exp()用法及代碼示例
- Groovy equals()用法及代碼示例
- Groovy before()用法及代碼示例
- Groovy pow()用法及代碼示例
- Groovy sin()用法及代碼示例
- Groovy concat()用法及代碼示例
- Groovy random()用法及代碼示例
- Groovy endsWith()用法及代碼示例
注:本文由純淨天空篩選整理自 Groovy - matches()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。