Java Split not working as expected
Posted
by daaabears
on Stack Overflow
See other posts from Stack Overflow
or by daaabears
Published on 2010-06-07T05:01:10Z
Indexed on
2010/06/07
5:22 UTC
Read the original article
Hit count: 204
I am trying to use a simple split to break up the following string: 00-00000
My expression is: ^([0-9][0-9])(-)([0-9])([0-9])([0-9])([0-9])([0-9])
And my usage is:
String s = "00-00000";
String pattern = "^([0-9][0-9])(-)([0-9])([0-9])([0-9])([0-9])([0-9])";
String[] parts = s.split(pattern);
If I play around with the Pattern and Matcher classes I can see that my pattern does match and the matcher tells me my groupCount is 7 which is correct. But when I try and split them I have no luck.
© Stack Overflow or respective owner