我一直想知道爲什麼字符"("
和")"
匹配模式"[\\p{Alpha} '-,.]"
。
請看看我的代碼。對於字符"("
和")"
,方法matches
將返回true
。
另外,如果我試圖匹配我的模式,是否還有其他字符會返回true
?Java正則表達式 - 字符「(」和「)」匹配模式「[\ p {Alpha}' - ,.]」
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
String pattern = "[\\p{Alpha} '-,.]";
//String text = "(";
String text = ")";
System.out.print(Pattern.matches(pattern, text));
}
}
我明白了。我已經擺脫了我的模式中的 - 符號。謝謝! –