0

我有这个代码:

$text = "###12###hello###43###good###113###thefinalstring";
preg_match_all('/(.*?)###(\d*)###(.*?)/is', $text, $matches, PREG_SET_ORDER);

如果我转储 $matches,为什么任何地方都没有“thefinalstring”?正则表达式的错误在哪里?

谢谢

4

2 回答 2

1
(.*?)###(\d*)###(.*?)([a-zA-Z]*)

使用这个正则表达式

于 2013-06-06T15:21:15.730 回答
0

试一试:

$text = "###12###hello###43###good###113###thefinalstring";
preg_match_all('/###(\d*)###([^#]*)/is', $text, $matches, PREG_SET_ORDER);
print_r($matches);

输出:

Array
(
    [0] => Array
        (
            [0] => ###12###hello
            [1] => 12
            [2] => hello
        )

    [1] => Array
        (
            [0] => ###43###good
            [1] => 43
            [2] => good
        )

    [2] => Array
        (
            [0] => ###113###thefinalstring
            [1] => 113
            [2] => thefinalstring
        )

)
于 2013-06-07T10:11:44.927 回答