基本上我正在阅读文档块中的自定义注释
/**
* This exception is thrown when no constant function is found.
*
* @author Time.ly Network Inc.
* @since 2.0
*
* @instantiator Ai1ec_View_Factory Category_Exception
* @package AI1EC
* @subpackage AI1EC.Config
*/
class Ai1ec_Constants_Not_Set_Exception extends Ai1ec_Exception {
}
我得到了文档块,然后尝试使用
$r = new ReflectionClass($tokens[$i][1]);
$doc = $r->getDocComment();
preg_match_all('#^.*.@instantiator\s+(.*?)\n#s', $doc, $annotations);
这实际上是有效的,但不是最佳方法.我试过了
preg_match_all('#^\s\\*\s?@instantiator\s+(.*?)\n#s', $doc, $annotations);
假设匹配一个空格,一个星号,零个或一个空格@instantiator一个或多个空格,然后得到任何内容,直到行尾,但它不起作用,没有匹配项.
另外我如何在正则表达式行的末尾修剪任何最终的空格?
解决方法:
您不需要s标志,也不需要双重转义,请尝试以下正则表达式:
preg_match_all('#^\s*[*]\s*@instantiator\s+(.*)$#im', $doc, $annotations);
标签:php,regex
来源: https://codeday.me/bug/20191122/2060478.html
6799

被折叠的 条评论
为什么被折叠?



