java - while(Matcher.find()) is looping infinitely -


i modified following code oracle's java tutorials:

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 text \"%s\" starting @ " + "index %d , ending @ index %d.%n", matcher.group(), matcher.start(), matcher.end());             found = true;         }         if(!found){             system.out.format("no match found.%n");         }     } } } 

i trying learn how use regular expressions in java. (i feel pretty confident regex's, not java's classes using them.) using eclipse, not incredibly familar with. not figure out how console not initialized null (as tutorial warned), removed , using static values , recompiling every time want try new.

when run code, infinite loop:

i found text "foo" starting @ index 0 , ending @ index 3. found text "foo" starting @ index 4 , ending @ index 7. found text "foo" starting @ index 8 , ending @ index 11. found text "foo" starting @ index 0 , ending @ index 3. 

etc., etc., etc. until hit terminate

what doing wrong?

thanks.

nevermind... >.< reason didn't see infinite loop on outside. assumed whole time other loop problem.

you have while(true) arround section of code. while(true) infinite loop, , never seem break out of it.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -