dougong5285 2013-03-02 12:46
浏览 30
已采纳

正则表达式匹配<cms:xxx />自定义html标记

I am developing own CMS and need to replace custom tags with proper php function.
my custom tags are like <cms:zone id="header" anotherAttr="attrValue" /> the <cms:xxx /> part is important to me.
so far i wrote this regex but its not working fine. <cms:?([\S|\s]*)\/>

<body>
        <cms:content id="footer" />

        <cms:zone id="header" />

</body>

it will match

<cms:content id="footer" />

            <cms:zone id="header" />
  • 写回答

1条回答 默认 最新

  • dongmiyu8979 2013-03-02 12:51
    关注

    Make the quantifier not greedy:

    <cms:?([\S\s]*?)\/>
           here __^
    

    and there're no needs for | inside the character class

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?