Re: Simple regex question
Bryan wrote:
If I have this:
my $v1 = "9"; #Needs to be "09"
my $v2 = "01"; # Okay
my $v3 = "3"; # Needs to be "03"
my $v4 = "54"; #Okay
I want to make sure that all strings have the same format, which is 2
digits (or more) but that single digit values are padded with a '0'.
This is for a database query that happens later.
What is the regex to convert "1" to "01" and leaves "101" alone?
You'd better use sprintf() for that.
perldoc -f sprintf
--
Gunnar Hjalmarsson
Email:
http://www.gunnar.cc/cgi-bin/contact.pl
.
Relevant Pages
- Simple regex question
... I want to make sure that all strings have the same format, which is 2 digits but that single digit values are padded with a '0'. ... This is for a database query that happens later. ... (comp.lang.perl.misc) - Re: Simple regex question
... I want to make sure that all strings have the same format, ... digits but that single digit values are padded with a '0'. ... This is for a database query that happens later. ... (comp.lang.perl.misc) - Re: Simple regex question
... Bryan wrote: ... I want to make sure that all strings have the same format, ... digits but that single digit values are padded with a '0'. ... (comp.lang.perl.misc) - Re: Formatting output
... I am trying to do formatted output of single digit decimals. ... //and my attempt to format the output ... You write a string; the third parameter is optional and is the number of bytes to write. ... You need fprintf() instead. ... (alt.php) - Re: Requiring a date be entered as mm/dd/yy on a form field.
... completely validate a date entered in this format. ... cultures often have difficulty even comprehending internationalizaion ... can easily be done and will cause some input errors to be corrected: ... For a common case of a single digit being off by one, ... (microsoft.public.scripting.jscript) |
|