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 replies to this topic
#1
Posted 28 September 2011 - 08:38 PM
|
|
|
#2
Posted 29 September 2011 - 09:49 AM
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...
Think that would do it. Now props :]
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
Posted 29 September 2011 - 10:52 AM
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.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









