[英]Java regex matcher pattern keep returning false
我在 Java 中遇到了正則表達式的一些問題。 我有這個正則表達式模式:
static Pattern parts = Pattern.compile("\\A([91|10|17|21|30].{1,20}\\s){1,5}\\Z");
然后我嘗試用虛擬數據測試它:
String s = "91448629517150623101408002301";
Matcher testMatcher = parts.matcher(s);
System.out.println(testMatcher.matches());
String s1 = "9143676601715Sep14101310147301";
Matcher testMatcher1 = parts.matcher(s1);
System.out.println(testMatcher1.matches());
虛擬數據的格式正確。 但是,我不確定為什么兩者都讓我返回 false。 有任何想法嗎?
您提供的正則表達式可能與模式匹配不正確。 我想你可能想使用\\s (一個空白字符)而不是\\S (一個非空白字符)。
我建議您再次仔細閱讀文檔。
例如,
static Pattern parts = Pattern.compile("\\A([91|10|17|21|30].{1,20}\\S){1,5}\\Z");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.