0
我有matcher的java代碼來查找使用mattcher.find方法的字符串中出現的次數。字符串matther正則表達式所需
下面是我的代碼
String text = "INCLUDES(ABC) EXCLUDES(ABC) EXCLUDES(ABC) INCLUDES(EFG) INCLUDES(IJK)";
String patternString = "INCLUDES(.)";
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher(text);
int count = 0;
while(matcher.find()) {
count++;
System.out.println("found: " + count + " : "
+ matcher.start() + " - " + matcher.end());
System.out.println(" - " +text.substring(matcher.start(), matcher.end()));
}
返回輸出
found: 1 : 0 - 9
- INCLUDES(
found: 2 : 42 - 51
- INCLUDES(
found: 3 : 56 - 65
- INCLUDES(
而不是我想正則表達式查找並返回出現次數爲包括:(*)
任何解決方案appriciated。預期的輸出應該是循環打印值
INCLUDES(ABC)
INCLUDES(EFG)
INCLUDES(IJK)
你只是想爲包括輸出?預期產出是多少? –
更新問題 –
這僅僅是缺少*之後。也許? –