in reply to phone number regex (new question)

food for thought from a newbie on your regex... this worked for a few of my tests, but i haven't fully experimented w/it.

i also tried to condense this w/references, but the script would either fail (due to nested quantifiers) or i'd rec'v my 'sorry you goofed' statement... the few ref's i could use didn't save much space. So, if anyone has a better way to revise this - feel free.

my $number =~ /^\s*1?(\.|\-)?\s*((\(|\[|\{)?\s*(\.|\-)?\s*\d\s*(\.|\-)?\s*\d\s*(\.|\-)?\s*\d\s*(\.|\-)?\s*(\)|\]\})?)?\s*(\.|\-)?\s*\d\s*(\.|\-)?\s*\d\s*(\.|\-)?\s*\d\s*(\.|\-)?\s*\d\s*(\.|\-)?\s*\d\s*(\.|\-)?\s*\d\s*(\.|\-)?\s*\d\s*(\.|\-)?\s*$/

(i know, it's sooo ugly.)

Basically breaks down like this:

^\s* #start/optional spaces 1?(\.|\-)?\s* #an optional 1- or 1. with optional spaces ( (\(|\[|\{)? #an optional bracket ( or { or [ \s*(\.|\-)?\s* #space or optional . or - \d\s*(\.|\-)?\s* #digit optional . or - and spaces \d\s*(\.|\-)?\s* # ditto \d\s*(\.|\-)?\s* # ditto (\)|\]\})? # choice of closing brackets )? # that section was optional \s*(\.|\-)?\s* #space or optional . or - \d\s*(\.|\-)?\s* #digit optional . or - and spaces \d\s*(\.|\-)?\s* # ditto \d\s*(\.|\-)?\s* # ditto \d\s*(\.|\-)?\s* # ditto \d\s*(\.|\-)?\s* # ditto \d\s*(\.|\-)?\s* # ditto \d\s*(\.|\-)?\s* # ditto $ # nothing more allowed
it'll yield numbers w/ or w/out a leading "1" - w/ or w/out an area code (w/ or w/out parantheses) then seven digits - all of which can be separated by white-space, a dash, or a dot ->
1.(234]-567.8.9.0.0 should be readable. You could then run it thru a loop to get it into a format you prefered, if ya wished (prob just removing everything 'cept digits would be easiest.) It's tough to account for every format a user would try, but this would do most.

knock-wood