regex - how to split a number without losing other same characters in Java -



using eclipse java , want split number without losing other same characters.

for example, input line is:
[1142,143,2142,142]

the output should that:
1142 143 2142


i using split("142|\\d+")but output showing this:
1 143 2

what should ?

you need use word boundaries.

string.split("\\b142\\b|\\d+"); 

or

do replace , split.

string.replaceall("\\b142\\b|[\\[\\]]", "").split(","); 

Comments