做了一個cms系統,有一些邏輯需要嵌套自定義的if標簽,目前正則運算式是這樣寫的
\{feather-cms:if[ \t]+.*\}([\s\S]+?)\{/feather-cms:if\}
這種單獨決議非嵌套沒有問題,能正確找到結束的標簽
{feather-cms:if test="('1' eq 1)"}
dfadsfadsf a
{/feather-cms:if}
但是遇到嵌套的,比如這種:
{feather-cms:if test="('1' eq 2)"}
{feather-cms:if test="('1' eq 1)"}
123
{/feather-cms:if}
{/feather-cms:if}
結束標簽就遇到了問題,這個正則該如何改進呢,謝謝大佬了!!
uj5u.com熱心網友回復:
\{feather-cms:if[ \t]+.*\}([\s\S]+?)
\{/feather-cms:if\}
你這個是三部分,那可以把前后部分分別圈起來加上 +,代表一次或多次
uj5u.com熱心網友回復:
不行吧,這個是嵌套的問題uj5u.com熱心網友回復:
比較笨的方法(\{feather-cms:if[ \t]+.*\}|[^\{feather-cms:if[ \t]+.*\}|\{/feather-cms:if\}]+|\{/feather-cms:if\})
語法沒驗證,意思就是每一部分單獨匹配出來,再寫個回圈遞回
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/284500.html
標籤:Web 開發
上一篇:后端接收引數問題
下一篇:linux tomcat