Remove leading zeros from a Number given as a string | Python3 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 re NEW_LINE def removeLeadingZeros ( str ) : NEW_LINE INDENT regex = " ^ 0 + ( ? ! $ ) " NEW_LINE str = re . sub ( regex , " " , str ) NEW_LINE print ( str ) NEW_LINE DEDENT str = "0001234" NEW_LINE removeLeadingZeros ( str ) NEW_LINE