regex to strip leading zeros treated as string

后端 未结 6 1299
灰色年华
灰色年华 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条回答
  •  萌比男神i
    2020-12-30 04:52

    You're almost there. You just need quantifier:

    str = str.replaceAll("^0+", "");
    

    It replaces 1 or more occurrences of 0 (that is what + quantifier is for. Similarly, we have * quantifier, which means 0 or more), at the beginning of the string (that's given by caret - ^), with empty string.

提交回复
热议问题