をループしている私はOracle's Java Tutorialsから、次のコードを修正:私はJavaで正規表現を使用する方法を学習しようとしていますしばらく(Matcher.find())無限
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class RegexTestHarness {
public static void main(String[] args){
while (true) {
Pattern pattern = Pattern.compile("foo");
Matcher matcher = pattern.matcher("foo foo foo");
boolean found = false;
while (matcher.find()) {
System.out.format("I found the text \"%s\" starting at " + "index %d and ending at index %d.%n", matcher.group(), matcher.start(), matcher.end());
found = true;
}
if(!found){
System.out.format("No match found.%n");
}
}
}
}
。 (正規表現についてはかなり自信がありますが、Javaクラスでは使用できません)Eclipseを使用しています。これは私にはあまり知られていません。コンソールをゼロに初期化しないように(私はチュートリアルで警告したように)コンソールを取得する方法を見つけられなかったので、静的な値を使用していて、何か新しいものを試してみるたびに再コンパイルしています。私は私が間違って何をやっている
終了当たるまで
I found the text "foo" starting at index 0 and ending at index 3.
I found the text "foo" starting at index 4 and ending at index 7.
I found the text "foo" starting at index 8 and ending at index 11.
I found the text "foo" starting at index 0 and ending at index 3.
など、など、など:私はこのコードを実行すると
は、私は無限ループを取得しますか?ありがとうございました。
Nevermind ...>。 <何らかの理由で、私は外に無限ループが見えませんでした。私はそれが問題だったもう一つのループであると全面的に仮定しました。
代わりに、あなたの受け入れ答えとして最も助け答えをマークしてください。質問を削除するよう求めています。それは他の初心者にとって有益かもしれません。 – alexcoco