简体   繁体   English

正则表达式嵌套的简码不起作用

[英]Regex Nested Shortcode Does Not Work

Can someone tell me why this does not work ? 有人可以告诉我为什么这行不通吗? - https://regex101.com/r/hJ5zN6/11 -https://regex101.com/r/hJ5zN6/11

Test string: 测试字符串:

[test][dzspgb_container][dzspgb_row][dzspgb_row_part part="1.4"][dzspgb_element text="whwaha" type_element="text"][/dzspgb_element][dzspgb_element text="test" type_element="text"][/dzspgb_element][/dzspgb_row_part][dzspgb_row_part part="1.4"][/dzspgb_row_part][dzspgb_row_part part="1.4"][/dzspgb_row_part][dzspgb_row_part part="1.4"][/dzspgb_row_part][/dzspgb_row][dzspgb_container]test second[/dzspgb_container][/dzspgb_container][/thisbreaks]

Test regex: 测试正则表达式:

*\[dzspgb_container(.*?)](.*?)\[\/dzspgb_container\](?!\s*\[\/)*

If we remove [/thisbreaks] from the string, it will work. 如果我们从字符串中删除[/thisbreaks] ,它将起作用。

It's because of the negative lookahead assertion at the end. 这是因为最后的否定超前断言。 I suggest you to remove that lookahead and use a greedy regex pattern like below. 我建议您删除该前瞻,并使用如下所示的贪婪正则表达式模式。

\[dzspgb_container(.*?)](.*)\[\/dzspgb_container\]

DEMO DEMO

(?!\\s*\\[\\/) asserts that the match won't be followed by ( zero or more space characters and a [ symbol ) (?!\\s*\\[\\/)断言,匹配后将不包含( 零个或多个空格字符和一个[符号 ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM