使用量词的多个正则表达式捕获组

时间:2011-05-16 13:05:35

标签: php regex

1 个答案:

答案 0 :(得分:9)

使用php,您可以使用preg_match_all

$str = '<td>Data 1</td>
<td>data 2</td>
<td>data 3</td>
<td>data 4</td>
';
preg_match_all('/(?:<td>(.+?)<\/td>\s*)/', $str, $m);
print_r($m);

<强>输出:

Array
(
    [0] => Array
        (
            [0] => <td>Data 1</td>

            [1] => <td>data 2</td>

            [2] => <td>data 3</td>

            [3] => <td>data 4</td>

        )

    [1] => Array
        (
            [0] => Data 1
            [1] => data 2
            [2] => data 3
            [3] => data 4
        )

)