Skip to main content
added 1 character in body
Source Link
Avinash Raj
  • 175.2k
  • 32
  • 247
  • 289

You need to use word boundaries.

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

OR

Do replace and thethen split.

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

You need to use word boundaries.

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

OR

Do replace and the split.

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

You need to use word boundaries.

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

OR

Do replace and then split.

string.replaceAll("\\b142\\b|[\\[\\]]", "").split(","); 
Source Link
Avinash Raj
  • 175.2k
  • 32
  • 247
  • 289

You need to use word boundaries.

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

OR

Do replace and the split.

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