Remove leading zeros from a Number given as a string | Java Program to implement the above approach ; Function to remove all leading zeros from a a given string ; Regex to remove leading zeros from a string ; Replaces the matched value with given string ; Driver Code
import java . util . regex . * ; class GFG { public static void removeLeadingZeros ( String str ) { String regex = " ^ 0 + ( ? ! $ ) " ; str = str . replaceAll ( regex , " " ) ; System . out . println ( str ) ; } public static void main ( String args [ ] ) { String str = "0001234" ; removeLeadingZeros ( str ) ; } }