Rnet
Rnet

Reputation: 5040

Java regex replace

I've a csv string like

"abc, java, stackoverflow  ,     stack exchange   , test"

Can I use regex to remove the space around the commas to get a string like

"abc,java,stackoverflow,stack exchange,test"

Upvotes: 14

Views: 20970

Answers (1)

C. K. Young
C. K. Young

Reputation: 223003

str = str.replaceAll("\\s*,\\s*", ",");

Upvotes: 29

Related Questions