Umar Draz wrote:
> I want to print all mobile from above string. Mobile code always start
> from 03. and not more than 4 digits.
> So here I have use this regular expression.
> while($str =~ /(\b(0([3](\d\d)))+[-]+\d{7}|\ b(0([3](\d\d)))+\d{7})/g){
> print "Your Mobile No. is " . $1 . "\n";
> }
> As you can see its not works because there is no space after the word is
> So would you please help me what kind of change is required in above
> regular expression.
#!/usr/bin/perl
use warnings;
use strict;
my $str = "" .
"Total Mobile HONDA Civic, EXI: model 2002, " .
"excellent condition, available for sale. My " .
"Phone # is. 042-6832797, My Cell. 0300-4459899, " .
"My Office Cell is0300-5009228, my other mobile " .
"no is 0356-4094030, my Friend Mobile no is . 03226789871";
while ($str =~ /(03\d\d).*?(\d{7})/g) {
my $area_code = $1 if $1;
my $phone_num = $2 if $2;
print "Your Mobile num is ${area_code}-${phone_num}\n";
}
__END__
prints this:
Your Mobile num is 0300-4459899
Your Mobile num is 0300-5009228
Your Mobile num is 0356-4094030
Your Mobile num is 0322-6789871
Steve
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/