Java では、Pattern と Matcher を使用して、一連の文字列内の ".A (数値)" のすべてのインスタンスを検索し、数値を取得しています。
ファイル内の単語の 1 つが "PAMX" で、数字が 0 を返すため、問題が発生します。ファイルの残りの部分は処理されません。さまざまな正規表現を使用してみましたが、「PAMX」の出現を超えて次の「.A (数値)」に進むことができません。
for (int i = 0; i < input.size(); i++) {
Pattern pattern = Pattern.compile("\\.A\\s\\d+");
Matcher matcher = pattern.matcher(input.get(i));
while (matcherDocId.find())
{
String matchFound = matcher.group().toString();
int numMatch = 0;
String[] tokens = matchFound.split(" ");
numMatch = Integer.parseInt(tokens[1]);
System.out.println("The number is: " + numMatch);
}
}