1
我寫了這個Java方法:爲什麼我的方法不適用於正則表達式?
public boolean checkPatternMatching(String sourceToScan, String searchPattern) {
boolean patternFounded;
if (sourceToScan == null) {
patternFounded = false;
} else {
Pattern pattern = Pattern.compile(Pattern.quote(searchPattern),
Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(sourceToScan);
patternFounded = matcher.matches();
}
return patternFounded;
}
現在我想檢查字符串,如 「A」。像這樣的方法調用返回一個錯誤的值,但爲什麼?
this.checkPatternMatching(stationShortcuts, "[a-zA-Z]")
我應該問你爲什麼用'[一-ZA-Z]'即使你使用'Pattern.CASE_INSENSITIVE'? – Keppil
@Keppil,好問題?喜歡它 – Keerthivasan