坚持使用正则表达式



来自另一个答案,我被正则表达式困住了(几率是多少...?

$matches    = array();
// $controller = $this->getRequest()->attributes->get('_controller');
$controller = "AcmeMyBundleControllerMyController::myAction";
preg_match('/(.*)\Bundle\(.*)\Controller\(.*)Controller::(.*)Action/', $controller, $matches);
print_r($matches);

退货(请参阅示例)

Array
(
)

预期成果

Array
(
    [0] => AcmeMyBundleControllerMyController::myAction
    [1] => Acme
    [2] => My
    [3] => My
    [4] => my
)

有人可以帮忙吗?这个正则表达式似乎是合法的,也许只是反斜杠的问题?我试了试,但没有得到。

请尝试以下表达式。这是意料之中的吗?或者告诉我你的确切要求。

<?php
$matches    = array();
// $controller = $this->getRequest()->attributes->get('_controller');
$controller = "AcmeMyBundleControllerMyController::myAction";
preg_match('/(.*)\(.*)Bundle\Controller\(.*)Controller::(.*)Action/', $controller, $matches);
print_r($matches);

最新更新