Java regex - overlapping matches -


in following code:

public static void main(string[] args) {     list<string> allmatches = new arraylist<string>();     matcher m = pattern.compile("\\d+\\d+\\d+").matcher("2abc3abc4abc5");     while (m.find()) {         allmatches.add(m.group());     }      string[] res = allmatches.toarray(new string[0]);     system.out.println(arrays.tostring(res)); } 

the result is:

[2abc3, 4abc5] 

i'd

[2abc3, 3abc4, 4abc5] 

how can achieved?

make matcher attempt start next scan latter \d+.

matcher m = pattern.compile("\\d+\\d+(\\d+)").matcher("2abc3abc4abc5"); if (m.find()) {     {         allmatches.add(m.group());     } while (m.find(m.start(1))); } 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -