Its hard to tell what you want since you didn't tell us specificaly. It appears however than you want to put the 0 on the front if there are only for digits? You could match for 5 and reverse your if statment or do the following.
my $test = "2123"; if($test=~/^\d{4}$/) { print "<td height=20 class=grtxt>0$test</td>\n"; } else { print "<td height=20 class=grtxt>$test</td>\n"; }
I removed the + since plus means 1 or more and your {4} means four. I then added ^ to the start and $ to the end, that means the regex will only match if it matches the whoel line. So it will only be happy if the string is 4 digits exactly. I'm still not sure this is the best solution since you repeated your HTML without cause. It would be far better to modify $test or have a second variable to hold the output string.
my $test = "2523"; $test = "0" . $test if($test=~/^\d{4}$/); print "<td height=20 class=grtxt>$test</td>\n";
In reply to Re: Regular Expression from Hell
by eric256
in thread Regular Expression from Hell
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |