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];


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.


94MSC xxxxx ,94120 00000

94MSC 94MSC ,94120 94120

94MSC consecutive Nos. ,94120 23456


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.
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

nitinsawhneyConnect With a Mentor Commented:

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;
        return 'Not a vanity number.';

Hope this gives you some hint.


molikjainAuthor Commented:
Thanks. It works for this sequence only


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.


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

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.


Molik Jain
All Courses

From novice to tech pro — start learning today.