php - 如何获取大括号内的嵌套值

标签 php regex

如何使用 php 进入嵌套大括号内?

例子:

{{ text1 {{text2 text3 {{text4}} text5}} }}

应该输出

1- text1 {{text2 text3 {{text4}} text5}}
2- text2 text3 {{text4}} text5
3- text4

最佳答案

这需要跟踪括号的数量,不能使用正则表达式来完成。您必须为此创建自己的解析器逻辑。 Regex is not a parser ,对不起。

Here is another similar question with the same response as mine

And here is a SO about building parses (in Java, but it should translate well enough)

关于php - 如何获取大括号内的嵌套值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11294144/

相关文章:

mysql - 从备份中恢复 Magento 静态 block 内容?

regex - 使用正则表达式确定顺子(无序手牌)

php - 除了 magic_quotes_gpc 之外的其他 PHP 插入转义字符的原因

Python:当字典键中有 ',' 时,为什么 re.sub 不将字典键替换为字典值

javascript - Jquery - trim 内部 HTML?

javascript - 如何使用正则表达式模式数组来检查 url

ruby - 零宽度否定后视断言无法按预期工作

php - 如何使用 PHP 重定向在新选项卡中自动打开外部链接?

php mysql全文搜索通过id连接的多个表

php - Mysql 之间比较一个字段?