我的正则表达式有一个错误,有人为我写的。我试图编写自己的正则表达式,但这对我来说很难破解。
我有一个自定义“标签”,例如 {module:agenda:getlist:params(2)} 但是.. 如果我只有 1 个参数,则正则表达式看不到 2,但得到了错误的代码。
这是我的正则表达式代码
$paramcount = preg_match_all('{
# [^,]+ everything that isn't a comma
# (?<=...) is a look behind. Meaning that the part that has the 3 dots
# becomes matched but not goes through the rest of the regex
# matches "null" in "params(null"
(?<=params\()[^,]+
| # this is the separation dash
# (?=...) is a look ahead, same as the look behind but than on the end
# matches "null" in " null)"
(?<= )[^,]+(?=\))
|
# matches "true" in ", true" and ""foo"" in ", "foo""
(?<=, )[^,]+
}x', $data, $parammatches);
所以当我尝试匹配它时..结果是:
$array = array
(
[0] => params(2
);
这不是我想要的,我只希望 2 匹配而不是其余的。当我给它更多像这样“params(null, 2)”的参数时,一切正常,我有 2 个不错的数组值。
有人可以在这里指导我或帮助我吗?
编辑:可以在 pastebin 上找到更多输出。 http://pastebin.com/x0WL9K4u