R . Pereira
R . Pereira

Reputation: 11

Replace leading and trailing commas as well as duplicate commas between words in a string

I am using the .replaceAll() function in java and want to use a expression in it to achieve the bellow result.

Input:-,,2000,,399,600,,,678,,

Output:-2000,399,600,678

Upvotes: 0

Views: 153

Answers (1)

vks
vks

Reputation: 67988

(?<=\\d)(,){2,}(?=\\d)|\\b,+\\B|\\B,+\\b

You can use this and replace by $1.See demo.

https://regex101.com/r/eB8xU8/7

Upvotes: 2

Related Questions