Jump to content

Phone number patterns

- - - - -

  • Please log in to reply
2 replies to this topic

#1
guyc2010

guyc2010

    Newbie

  • Members
  • Pip
  • 1 posts
Hi Experts,

I am trying to write a script which can summarize the phone number ranges into patterns. For example,

a number range: 1000 ~ 1099, its pattern is: 10XX, where x stands for any digits in (0~ 9)
another range: 1200 ~ 1999, its pattern is 1[2-9]XX, where, [2-9] means any digits in (2~ 9)
more complex: 2301 ~ 4001, it's pattern is:
230[1-9], ==> all numbers from 2301 to 2309
23[1-9]X, ==> all numbers from 2310 to 2399
2[4-9]XX, ==> all numbers from 2400 to 2999
3XXX, ==> all numbers from 3000 to 3999
400[01] ==> all numbers from 4000 to 4001

Do you have any good idea how the algorithm shall be to achieve that? I mean, enter any number range with the starting and ending numbers, then the script will generate its approriate pattern/patterns.

Any input/suggestions is much appreciated.

#2
Mentalbox

Mentalbox

    Newbie

  • Members
  • PipPip
  • 19 posts
Regex: 10[0-9][0-9], 1[2-9][0-9][0-9], etc? Easy peasy :D
I like Perl, and Perl supports regex. Might wanna check that out, I don't know - just whatever language that supports regex and file R/W :P

Concept would be kind of like...
my @trolololol;
while(!EOF){ #not actual code, but what this says is: while not end of file
...read first/next line from file... #replace with actual code here
if <line> =~ /10[0-9][0-9]/{ #'<line>' is not actual code
my $x = ...get value of current line... #again, replace with actual code
$trolololol[$x] = <line>; #again, '<line>' is not actual code
}
}

Think that would do it. Now props :]

#3
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Start by getting ranges of contiguous numbers. Don't worry about the regex-y output, worry first about identifying things like "1000-1099". Also, you may want to clarify what types of patterns you want to support. Having a pattern like 10[2-4]7 is meaningful, but perhaps not useful.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users