四非匹配
在正則表達式中我們往往需要在字符串中進行非匹配這時就要通過^進行匹配條件限制^的常見入門用法如下:
[^az] 條件限制在非小寫a to z范圍中一個字符
[^AZ] 條件限制在非大寫A to Z范圍中一個字符
[^azAZ] 條件限制在非小寫a to z或大寫A to Z范圍中一個字符
[^] 條件限制在非 to 范圍中一個字符
[^az] 條件限制在非 to 或a to z范圍中一個字符
代碼示例如下:
public class RegExp {
private Pattern patt;
private Matcher matcher;
public boolean squareReg(String regStrString regex){
return monRegExp(regStr regex);
}
private boolean commonRegExp(String regStrString regex){
boolean wildcard_Res=false;
patt=pile(regex);
matcher=pattmatcher(regStr);
wildcard_Res= matcherfind();
return wildcard_Res;
}
}
public class TestRegExp {
public static void main(String[] args) {
RegExp re=new RegExp();
boolean wildcard_Res=false;
wildcard_Res=resquareReg(tcn t[^aoe]n);
Systemoutprintln(wildcard_Res);
//輸出:wildcard_Res=true
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/25692.html