坚持正则表达式

时间:2014-04-04 04:11:35

标签: php regex

来自另一个答案,我坚持使用正则表达式(有什么可能性......?)。

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

print_r($matches);

返回(see example

Array
(
)

预期结果

Array
(
    [0] => Acme\MyBundle\Controller\MyController::myAction
    [1] => Acme
    [2] => My
    [3] => My
    [4] => my
)

任何人都可以提供帮助?这个正则表达式似乎是合法的,也许它只是反斜杠的一个问题?我试过了但没有得到它。

1 个答案:

答案 0 :(得分:2)

请尝试以下表达方式。这是预期的吗?或者告诉我你的具体要求。

<?php

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

print_r($matches);