PHP模式搜索

Im trying to search for nn/nnnnnn/nn in a file..

I have this

if (preg_match_all("([0-9]{6})", $file, $out)) {
echo "Match was found <br />";
print_r($out);

which deals with the centre 6 numbers but how do I get it to search for the whole pattern? I get a little confused when i have to add the search strings together. I know I have to do the following

([0-9]{2}) and / and ([0-9]{6}) and / and ([0-9]{2})

HOw do I add the search string as one? Thanks in advance Cheers Mat

Have you tried:

preg_match_all("/([0-9]{2})\/([0-9]{6})\/([0-9]{2})/")

If searching 12/123456/12, for example, it will output:

Array
(
    [0] => Array
        (
            [0] => 12/123456/12
        )

    [1] => Array
        (
            [0] => 12
        )

    [2] => Array
        (
            [0] => 123456
        )

    [3] => Array
        (
            [0] => 12
        )

)

Try this #(\d{2})/(\d{6})/(\d{2})#:

$file = '23/334324/23';
if (preg_match_all("#(\d{2})/(\d{6})/(\d{2})#", $file, $out)) {
    echo "Match was found <br />";
    print_r($out);
}

Returns:

Array
(
    [0] => Array
        (
            [0] => 23/334324/23
        )

    [1] => Array
        (
            [0] => 23
        )

    [2] => Array
        (
            [0] => 334324
        )

    [3] => Array
        (
            [0] => 23
        )

)

You can also use \d for a digit instead:

preg_match_all("#(\d{2})/(\d{6})/(\d{2})#", $string, $matches);
print_r($matches);

How about using #([0-9]{2})/([0-9]{6})/([0-9]{2})#:

if(preg_match_all("#([0-9]{2})/([0-9]{6})/([0-9]{2})#", $file, $out)) 
{
    echo "Match was found <br />";
    print_r($out);
}