in reply to Re: RegEx to remove leading zeros from a hex number
in thread RegEx to remove leading zeros from a hex number

... and gets rid of all zeros. D'oh!
use warnings; use strict; my $var = '0000'; $var =~ s/^0+//g; print ">>>$var<<<\n"; __END__ >>><<<

Replies are listed 'Best First'.
Re^3: RegEx to remove leading zeros from a hex number
by JavaFan (Canon) on May 16, 2011 at 21:24 UTC
    Well, yes. Removing the leading zeros from a string containing only zeros leaves zero zeros. What you do you think should happen? Leaving a string with leading zeros, or a string containing non-zeros? Neither seems to be correct.
      Write a sub. It is "not nearly as 'clever' as one might think" to write a regex one-liner. A clearly commented subroutine, that includes whatever if-statements it may need to clearly and obviously do its job, is much to be preferred.