Android/Java Regex to remove extra zeros from sub-strings

前端 未结 7 1344
闹比i
闹比i 2020-12-16 17:04

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 :

         


        
7条回答
  •  攒了一身酷
    2020-12-16 17:48

    \.0+$|^(-)?0+(?=\.)
    

    You can try this.Replace by $1.if u get empty string or - after replacement replace it by 0.See demo.

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

    If you want to do on full string use

    -?0*\.0+\b|\.0+(?=,|$)|(?:^|(?<=,))(-)?0+(?=\.)
    

    See demo.

    https://regex101.com/r/cZ0sD2/16

提交回复
热议问题