Vanity Number search in php, regex

I want to develop a script in PHP using regex and I have a database of indian mobile no's, that will search for vanity numbers list in .txt, and a vanity no. is like 94161 55555, 94161 66666 and so on.

I used this script

            $regex = "[0-9]{5}";
            if (eregi($regex, $fline , $matches))
            {
                  echo "Match was found ". $fline . "<br />";
                  //echo $matches[0];

                  $c++;
            }


But it shows me all the numbers. I have tried many combinations of regex, but of no use. What to do, Please help me.

Further there are many kind of vanity number types like mentioned below. Here all the sequence styles with examples are given.

Sequence,Example

94MSC xxxxx ,94120 00000

94MSC 94MSC ,94120 94120

94MSC consecutive Nos. ,94120 23456

94MSMSMSMS,9412121212

94MSC axxxx ,94120 30000

94MS xyxyxy ,9412 03 03 03

94MSCx MSCx ,94 1200 1200

94MSC 94(MSC+1) ,94120 94121

94MSCa b000 ,941203 4000

94MSCa consecutive nos ,941204 3456

94MSC MSC MS (2 digit) ,94120 120 12

94MSC CSM49 (Mirror) ,94120 02149

94MS xy (xy+1) (xy+2) ,9412 14 15 16

94MS xxx yyy ,9412 000 111

and I want my script to cover all these aspects.

Any clue for full script or guidelines so that I can develop it on my own. Let me tell you that, I know php good, but I am not an expert in regex.

Thanks in advance.
molikjainAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nitinsawhneyCommented:
Hi,

You will never be able to achieve it with one regex or regex alone;
The idea is to pass the number to a function which checks each of the pattern mentioned above.

Here is logic for just checking if last 5 digits number are same.

function checkNumber($number) {
//Asuming in India there are 10 digit mobile numbers
    if ($number{9} == $number{8} && $number{9} == $number{8} && $number{9} == $number{7} && $number{9} == $number{6} && $number{9} == $number{5}){
        return $number;
    }
    else{
        return 'Not a vanity number.';
    }
}

Hope this gives you some hint.

Cheers.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
molikjainAuthor Commented:
Thanks. It works for this sequence only

Sequence,Example

94MSC xxxxx ,94120 00000

Can you please explain me the above solution.

And this was one part of it.

and I will be really greatful, if you can give the similar solution for all my sequence requirements.

Regards

Molik Jain
0
molikjainAuthor Commented:
It was simple, and I missed this simple syntax in php. But I would appreciate Nitin Sawhney for this.

Thanks.
0
molikjainAuthor Commented:
I am now able to complete the rest of the sequences. But if I need more help, I hope you would help in Nitin in the future.

Regards

Molik Jain
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.