nix, shell, perl, php, mysql and mac os x tips and tricks

Thursday, December 2, 2010

Strip leading zeroes using regex

Doesn't actually "strip", rather captures the non-laeding-zero number. Works only on a string that only contains numbers, and is compatible with ancient regex versions.
^[0]+([1-9][0-9]{1,})$
NOTE: will NOT match a number that doesn't have leading zeroes

No comments:

Post a Comment