I have the following string as input :
"2.0,3.00,-4.0,0.00,-0.00,0.03,2.01,0.001,-0.03,101"
Final output will be like :
"2,3,-4,0,0,.03,2.01,.001,-.03,101"
i.e. all leading and trailing zeros will be removed and both positive/negative zeros will be simply zero.
We can achieve this by split the string first and using Regex for each part. But my string size is more than 10000.
How can we achieve this using Regex
?
Edit:
Analysis of Answers:
I have tested all answers with String "0.00,-0.00,00.00,-00.00,40.00,-40.00,4.0,-4.0,4.01,-4.01,04.01,-04.01,004.04,-004.04,0004.040,-0004.040,101,.40,-.40,0.40,-0.40"
and answer from Wiktor Stribiżew passed all the test cases .(see here : https://regex101.com/r/tS8hE3/9 ) Other answers were passed on most of the cases but not all.