【发布时间】:2013-05-25 20:32:18
【问题描述】:
5 月 26 日更新
我已经修复了之前包含在这个问题中的正则表达式的行为,但是正如其他人所提到的,我的语法仍然不正确。显然它编译的事实是由于 PHP 的 preg_* 系列函数忽略了我的错误。
我绝对是 PCRE 新手,所以我试图了解存在哪些错误,以便我可以着手修复它们。我也愿意对设计/方法进行批评,正如其他人所提到的,我还将构建与 JSON 和 YAML 的兼容性,但我想继续完成这个自制的解析器,因为我有了它工作,我只需要处理表达式语法(我认为)。
这是从整页代码中提取的所有preg_match_all 引用和一个preg_replace 引用:
// matches the outside container of objects {: and :}
$regex = preg_match_all('/\s\{:([^\}]+):\}/i', $this->html, $HTMLObjects);
// double checks that the object container is removed
$markup = preg_replace('/[\{:]([^\}]+):\}/i', '$1', $markup);
// matches all dynamic attributes (those containing bracketed data)
$dynamicRegEx = preg_match_all('/[\n]+([a-z0-9_\-\s]+)\[([^\]]+)\]/', $markup, $dynamicMatches);
// matches all static attributes (simple colon-separated attributes)
$staticRegEx = preg_match_all('/([^:]+):([^\n]+)/', $staticMarkup, $staticMatches);
如果您想在上下文中查看 preg_match_all 和 preg_replace 引用,以便您也可以评论/批评,您可以通过以下链接查看包含的源文件。
注意:查看页面的源代码可以使所有内容更具可读性 http://mdl.fm/codeshare.php?htmlobject
就像我说的,我让它按现状运行,我只是要求对我的 PCRE 语法进行监督,以免它不合法。但是,如果您在结构/设计或其他方面有 cmets,我愿意接受所有建议。
【问题讨论】:
标签: php regex preg-match preg-match-all pcre