in reply to Pull 3-digit and 4-digit numbers from string

As others have posted, much depends on the exact definition of a "phone" or "apartment" number. The following works well, except see what happens with a "phone" number like "123.345-5678"; is such a character sequence possible? This uses the regex enhancements of Perl version 5.10.

c:\@Work\Perl\monks>perl -wMstrict -le "use 5.010; ;; my $s = 'Sent to 1402, 222-2222, 1304, 555.555.5555 and 501, 666 666 6666, +123-345.5678'; ;; my $sep = qr{ [-. ] }xms; my $pn = qr{ \d{3} ($sep) (?: \d{3} \1)? \d{4} }xms; my $an = qr{ \d{3,4} }xms; ;; my @caps = $s =~ m{ (?| $pn (*SKIP)(*F) | (?<! \d) ($an) (?! \d)) }xmsg; ;; printf qq{'$_' } for @caps; " '1402' '1304' '501' '123'


Give a man a fish:  <%-(-(-(-<