今天剛剛看了String.match的用法,時間不長,代碼不長,不過可以記錄一下,方便大家
match()的參數一般為正則表達式,現在兩個正則表達式,可以試用
正則表達式一:可以適用任何形式的字符串,
其中LikeType是要匹配的字符串,patten是生成的正則表達式,sourceStr是已有字符串,判斷sourceStr是否滿足LikeType的正則表達式
public static void main(String[] args) {
  // TODO Auto-generated method stub
  String likeType = "23";
  String pattern = "[a-zA-Z0-9]*[" + likeType + "]{1}[a-zA-Z0-9]*";
  String sourceStr = "adfjaslfj23ldfalsf";
     System.out.println(sourceStr.matches(likeType)); 
 }

正則表達式二:固定位置的字符串匹配,理解同上,只是正則表達式的不同
public static void main(String[] args) {
  // TODO Auto-generated method stub
  String likeType = "%%%23%%%*";
  String sourceStr = "423236664";
  likeType = likeType.replaceAll("%", "\\\\d").replaceAll("\\*", "\\\\d\\*");
  System.out.println(likeType);
     System.out.println(sourceStr.matches(likeType)); 
 }
match的方法比較簡單,但絕對實用,所以要掌握用法,正則表達式的寫法尤其重要。
就這些吧,上面的代碼可以直接使用,歡迎測試