I am trying to strip all leading zeroes but retain one from strings . for eg:
if string is 000111 return 0111
if string is 00111 return 0111
if string is 0111 return 0111
if string is 1111 return 1111
the regex is working good, but if my string is say "3001" then the regex is returning 301 instead of 3001.
scala> "00111".replaceAll("[0]*(0\\d+)", "$1")
res9: String = 0111
scala> "0111".replaceAll("[0]*(0\\d+)", "$1")
res10: String = 0111
scala> "3001".replaceAll("[0]*(0\\d+)", "$1")
res11: String = 301
What am I missing here???