/*正則表達式:replaceAll(),matches()的運用
replaceAll()將符合正則表達式的字符串置換為指定的字符串,matches()驗證字符串是否符合指定的正
則表達式,split()可以將不符合條件的字符串留下,將符合條件排除*/
import java.io.*;
public class RegularExpression{
public static void main(String[]args)throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("abcdefgabcabc".replaceAll(".bc","###"));
String phoneE="[0-9]{4}-[0-9]{6}";
System.out.println("輸入手機號:");
String input=br.readLine();
if(input.matches(phoneE))
System.out.println("格式正確");
else
System.out.println("格式錯誤");
}
}
posted on 2009-03-28 18:14
鵬凌 閱讀(213)
評論(0) 編輯 收藏