Well, it looks like your regular expression really needs some help.
To begin with, you asked why $3 has nothing. That is because there is no $3. From the match you specified, you only have two sets of (). The first one is $1 and the second one is $2. You did not specify anything to be saved as a $3. You could re-write the match to be the following, but please keep in mind that this is untested and might need some tweaking:
-
$var="test.tc__na1me_1.20080616184340025";
-
if($var=~/^\d+_+(a-zA-Z0-9)+_+.+$/)
-
{
-
print $1;
-
-
}
-
If the above code works, it will print out the na1me that you expected. Albeit, the code is a little greedy, but it will hopefully get the job done. If I have time to test it, I will do so and correct any errors. But, in the middle match (a-zA-Z0-9), you mentioned special characters, you would have to specify exactly which special characters to look for, or you could possibly do it like this: (\w\W)*
but again, that's untested and I don't have a sample containing special characters from you either.
Regards,
Jeff
**Update: Ok, that regex doesn't work. I notice now some issues with it, but don't have the time right now to look at it. If someone else has the answer for the OP, please post it.