使用正则表达式识别 WordPress 短代码
我有一个 WordPress 短代码,其中包含一些其他短代码。当执行第一个短代码时,我想使用正则表达式过滤掉其他短代码。
[main_code]
[sub_code id='testid']test content[/sub_code]
[sub_code id='testid' name='testname']test content[/sub_code]
[/main_code]
当我执行 main_code 时,我想将 sub_code 过滤到数组中并访问其属性,而不将 sub_code 作为短代码执行。
任何有知识可以为我提供解决方案的人都会受到高度赞赏。
I have a wordpress shortcode which contains some other shortcodes inside it. When the first shortcode is executed i want to filter out other shortcodes using a regex.
[main_code]
[sub_code id='testid']test content[/sub_code]
[sub_code id='testid' name='testname']test content[/sub_code]
[/main_code]
When i execute the main_code i want to filter the sub_code into an array and access its attributes without executing sub_code as a shortcode.
Anyone who has knowledge to give me a solution is highly appriciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想匹配内部部分,那么我建议:
[^\[\]]
匹配任何不带方括号的内容。因此可以确保其中不能存在其他短代码。If you want to match the inner parts, then I'd advise:
The
[^\[\]]
matches any content without square brackets. So it's ensured no other shortcodes can exist within.