Re: Simple regex question



s/^(\d)$/0$1/;

"Bryan 写道:
"
Hi,

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?

.



Relevant Pages

  • 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)
  • 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: Formatting output
    ... I am trying to do formatted output of single digit decimals. ... //and my attempt to format the output ... You need fprintf() instead. ... Why would it be an undefined function? ...
    (alt.php)
  • Re: fixing time column
    ... column the single digit hours stay single digit when they should be padded ... When I move the cursor over the cell with "8:03" the cell in the formula bar ... I want to format times with single digit hours (like ... > Tracey wrote: ...
    (microsoft.public.excel)