Dear User!

I want to get all telephone and mobile number from a string and save into a 
variable. Here is my example what i am doing.

#!/usr/bin/perl

$str = "This is my string my mobile number is 0300-4459899, 042-8494949 
041-8580880 now the string is complete"
 while($line =~ /(([0-9]{3,4}[-]?)?[0-9]{7})/g){
   $tel =  $1
}

Now the above code is working file for me all telephone numbers and mobile 
number are saved in $tel. 

No my question is how to handle spaces e.g

$str
= "This is my string my mobile number is 042-6715171 0 30 0- 4 4 5 9 8
9 9,  0 42-84 94 94 9, 0 4 1 - 85 80  8 8 0 now the string is complete"
while($line =~ /(([0-9]{3,4}[-]?)?[0-9]{7})/g){

   $tel =  $1

}


now this time only (042-6715171) are saved in $tel variable.

Would you please help me to solve this issue.

Regards,

Umar


      

Reply via email to