regex - Pattern and Matcher in Java: Matcher only finds one match instead of two -


this question has answer here:

i'm working pattern , matcher in java. have following code:

string searchstring = "0,00,0"; string searchintext = "0,00,00,0" pattern p = pattern.compile(searchstring); matcher m = p.matcher(searchstring); while(m.find){   ...  } 

my problem matcher finds 1 match first 0 4th zero. there should match 3rd 0 last zero.

can me? there workaround?

getting overlapping matches regex tricky, if you're not familiar regexes.

if you're not using regex functionality (like in example), indexof(string, int) , keep increasing index you're doing search.

int index = 0; while((index = text.indexof(pattern, index)) > -1) {     system.out.println(index + " " + pattern);     index++; } 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -

Python Tornado package error when running server -