java - How to split a string with preceding Zeros using regular expression? -
how can split string a000101
a000 , 101
, 000101 000 , 101
using same regular expression.
i tried "a000101".split("(?<=\\d)(?=\\d)|(?<=\\d)(?=\\d)&(?!=0)")
output a , 000101
edit :
can a0000
, 0
a00000
using same logic ?
it seems easier me use matcher
instead of split
:
string str = "a000101"; pattern p = pattern.compile("([^1-9]*)([1-9]\\d*)"); matcher m = p.matcher(str); if (m.matches()) { string prec = m.group(1); string post = m.group(2); }
Comments
Post a Comment