String中matches用法

public boolean methes(String regex)

此方法是:字符串是否匹配給定的正則表達式

用法:str.methes(regex);

例子1 public static void main(String args[]){
String a = "0";
String b = "\\d";
System.out.println(a.matches(b));
}

注:\\d表示0—9數字,所以a.matches(b)放回true。

例子2: public static void main(String args[]){
String a = "99(jhkh00";
String b = "^[a-zA-Z0-9]+$";
System.out.println(a.matches(b));
}

注:放回false


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章