preg_match pcre regexp

时间:2013-02-07 18:02:46

标签: php preg-match

我有一个小问题写了正确的reg exp,我有一个字符串

2013-01-11 17:38:02.137759 some text leater

11 Jan 17:38:02 some text leater

所以我写了一个reg exp

(?:(?:(?:\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}(?:\.\d+)?)\s(?:[^\s]+)\s(?:.\d+.)?\s?))?((?:(\d{4}-\d{2}-\d{2})\s\d{2}:\d{2}:\d{2}(?:\.\d+)?)|(?:(\w{3}\s+\d+)\s\d{2}:\d{2}:\d{2})) 

示例结果是:

Array
(
    [0] => Array
        (
            [0] => Jan 11 17:38:02
        )

    [1] => Array
        (
            [0] => Jan 11 17:38:02
        )

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

    [3] => Array
        (
            [0] => Jan 11
        )

)

Array
(
    [0] => Array
        (
            [0] => 2013-01-11 17:38:02.137759
        )

    [1] => Array
        (
            [0] => 2013-01-11 17:38:02.137759
        )

    [2] => Array
        (
            [0] => 2013-01-11
        )

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

)

问题是结果我想跳过空场结果我该怎么做?

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

最简单的方法就是在结果上使用array_filter

array_filter($array, function ($piece) { return array_filter($piece); });