Home: Perl Programming Help: Regular Expressions:
Finding Amount of digits Matching

New User

Sep 13, 2007, 1:40 AM

Views: 7333
 Finding Amount of digits Matching
Hi,I have the following problem.

Say i have a code 002577.

I want to match this agains a big number of regular expressions and find the best match.Say the best matches is the following.

002577[6-9][0-5]
00257795[5-9]
002577[6-9][6-9]

My problem is that 002577 is less digits that all three these regular expressions.Thus something like

 Code
`002577 =~ 002577[6-9][0-5] 002577 =~ 00257795[5-9] 002577 =~ 002577[6-9][6-9]`

does not match in any case.I would like my script to realize that the 002577 matches the first part of the regular expression and return me with the amount of digits matching.

I have a generel script that matches a lot of regular expressions(most the code i want match is longer than the regular expressions,so it works mostly,but in cases like the above i run into problems.)

Any idea how I can fix this.Any help will really be appreciated.

Thanks

KevinR
Veteran

Sep 13, 2007, 8:59 AM

Views: 7328
 Re: [baddah] Finding Amount of digits Matching
Your question and examples are not making sense to me.
-------------------------------------------------

New User

Sep 13, 2007, 9:11 AM

Views: 7327
 Re: [KevinR] Finding Amount of digits Matching

Sorry,i'll try to rephrase.I have a table of regular expressions(all represent phone numbers/codes).No i have a code,and i am traversing through the table and i want to find a match.
I want my script to give me back all matches for a code(002577 in this case).

002577 has 6 digits,so it must look for all regular expressions where the first 6 digits match.Thus 002577[6-9][0-5] will match because the first 6 digits of the regular expression are the same.(It must not look at the [6-9][0-5] part,because the code i'm looking for only has 6 digits)

00257795[5-9] and 002577[6-9][6-9] will match for the same reasons.Their first 6 digits match the code i'm looking for.(002577)

The script must just take the code(002577) and get the amount of digits(6) and look at the all the regular expressions i have in my table,but only the first 6 digits.

I hope this makes more sense,Please let me know if it does not.i really would appreciate help with this.

Thanks

KevinR
Veteran

Sep 13, 2007, 9:26 AM

Views: 7325
 Re: [baddah] Finding Amount of digits Matching
Let me see the table of regexps, maybe that will help me to undestand your question.
-------------------------------------------------