regex to strip leading zeros treated as string

后端 未结 6 1302
灰色年华
灰色年华 2020-12-30 04:28

I have numbers like this that need leading zero\'s removed.

Here is what I need:

00000004334300343 -> 4334300343

000

6条回答
  •  情歌与酒
    2020-12-30 05:07

    Accepted solution will fail if you need to get "0" from "00". This is right one:

    str = str.replaceAll("0+(?!$)", "");
    

    "^0+(?!$)" means match one or more zeros if it is not followed by end of string.

提交回复
热议问题