string phone = "13528283535";
//檢測是否是手機號
system.out.println(phone.matches("^(13|15|18)\\d$"));
string a = "b";
string b ="1";
string c ="+";
string d="ac1";
string e="ab";
string f="";
//[abc]: 表示可能是a,可能是b,也可能是c
system.out.println(a.matches("[abc]"));
//[^abc]:表示不是a,b,c中的任意乙個
system.out.println(a.matches("[^abc]"));
//[a-za-z]:表示是字母
system.out.println(a.matches("[a-za-z]"));
//[0-9]:表示是否是數字
system.out.println(b.matches("[0-9]"));
//.:匹配任意字元
system.out.println(".:"+a.matches("."));
system.out.println(".:"+b.matches("."));
system.out.println(".:"+c.matches("."));
//\d:表示非數字 需要新增轉義符\ 列印\t \d \d \n什麼的都需要轉義符\
system.out.println("\\d:"+c.matches("\\d"));
system.out.println("\\d:"+e.matches("\\d"));
//\d:表示數字
//\s:表示由空字元組成,[ \t\n\r\x\f]
//\s:表示由非空字元組成,[^\s]
//\w:表示字母、數字、下劃線,[a-za-z0-9_]
//\w:表示不是由字母、數字、下劃線組成
//?: 表示出現0次或一次
system.out.println(f.matches("[d]?"));
system.out.println(b.matches("[1]?"));
system.out.println("?:"+b.matches("\\d?"));
string g="123";
//+:表示出現多次
system.out.println("+:"+g.matches("\\d+"));
//\d、[0-9]:表示是3個數字
system.out.println(g.matches("\\d"));
system.out.println(g.matches("[0-9]"));
system.out.println(g.matches("[0-9]*"));
//[a-z]:表示三個小寫字母 [a-za-z]表示三個字母
//1.?: 表示出現0次或1次
//2.+: 表示出現1次或多次
//3.*: 表示出現0次、1次或多次
//4.:表示出現n次
//5.:表示出現n~m次
//6.:表示出現n次或n次以上
//^:表示非
//food|f:表示匹配food或者foof
//(food)|f:表示匹配food 或者f
string i = "123456";
system.out.println(i.matches("\\d"));
system.out.println(g.matches("\\d"));
string j = "acd";
system.out.println(j.matches("ac"));
system.out.println(j.matches("acd"));
string str = "12y34h56dad7";
//匹配所有字母
string regex = "[a-za-z]+";
//替換
str =str.replaceall(regex,"-");
system.out.println(str);//12-34-56-7
string str1 = "tom:30|jerry:20|bob:25";
string reg = "\\|"; //匹配所有|
//拆分
string arr = str1.split(reg);
system.out.println(arrays.tostring(arr));//[tom:30, jerry:20, bob:25]
//驗證:boolean matches(string regex)
//拆分: string split(string regex)
//替換: string replaceall(string regex, string replacement)
//用regex的to去查詢input to前的位數
string regex = "to";
string input = "welcome to yiibai.com";
pattern pattern = pattern.compile(regex);
matcher matcher = pattern.matcher(input);
while(matcher.find()) {
system.out.println("pattern string start(): " + pattern);
system.out.println("match string start(): " + matcher);
system.out.println("match string start(): " + matcher.start());
Java學習之路(四)流程控制
順序結構是最簡單也是最基礎最常用的程式結構,執行順序是自上而下,依次執行。選擇結構即if else結構和switch結構。if else結構 if 結構if true system.out.println true if else結構 int i 0 if i 0 else 多重if結構 int j...
TCP IP學習之路(四)
ip協議提供了一種分層的 與硬體無關的定址系統,具有在複雜的路由式網路中傳遞資料所需的服務。tcp ip網路上的每個網路介面卡都有唯一的ip位址。網路上的ip位址具有一定規則,因此我們可以通過檢視ip位址來了解主機的位置。ip被分為兩個部分 網路id與主機id 網路必須提供一種方式來判斷ip位址的哪...
Java學習之路 mySQL
命令列 create database 資料庫名 use 資料庫名 drop database 資料庫名 建立表 create table 表名 屬性1 型別,屬性2 型別,顯示所有存在的表 show tables 顯示特定表的格式 即有什麼屬性 describe 表名 插入一項資料 insert ...