
witnesstheday
New User
Dec 3, 2008, 12:49 PM
Post #6 of 6
(1698 views)
|
|
Re: [rohan076] Phone Number parsing Help
[In reply to]
|
Can't Post
|
|
This minor adjustment to the original code also sort of works:
my $a="123-3456, 895-4839484, 84938932-4483938, 489-2834"; while ( $a =~ /(\d{3}-\d{4}\D)/g ) { print "$1\n"; } i.e. sticking \D at the end, so it's followed by a nondigit I had one at the start too, but it didn't count \A as \D, and if one put in \A it'd miss ones hypothetically later you could have two if you wanted to include the start, i.e. one with \D and one with \A
#!/usr/bin/perl my $a="123-3456, 895-4839484, 345-2323 84938932-4483938, 489-2834"; while ( $a =~ /(\D\d{3}-\d{4}\Z)/g){ print "$1\n"; } while ( $a =~ /(\A\d{3}-\d{4}\D)/g){ print "$1\n"; } while ( $a =~ /(\D\d{3}-\d{4}\D)/g){ print "$1\n"; } is a painful but working way through, I found however now I have tried the \b, and I have realised that obviously that's the best way, I just never used \b's enough so far. Still, my way works too, but is a bit messy. Just thought I'd have a go.
(This post was edited by witnesstheday on Dec 3, 2008, 1:02 PM)
|