Tuesday, 15 June 2010

java - String split with regex -



java - String split with regex -

i want take string according regex in java. suppose have string "r12t12w5p12t5l3" . , want have : mystr[0]="r12t12",mystr[1]="w5p12",mystr[2]=t5l3. want have regex first character number 1 time again character , lastly number. how can that?

string s="r12t12w5p12t5l3"; string regex = "([a-z]\\d+){2}"; pattern p = pattern.compile(regex); matcher m = p.matcher(s); while(m.find()){ system.out.println(m.group(0)); }

this print

r12t12 w5p12 t5l3

you can set them list , convert array @ end.

java regex tokenize

No comments:

Post a Comment