How to remove `//<![CDATA[` and end `//]]>` with javascript from string?

后端 未结 3 1168
一个人的身影
一个人的身影 2021-01-17 18:40

How to remove // and end //]]> with javascript from string?

var title = \"

        
3条回答
  •  难免孤独
    2021-01-17 19:10

    I suggest this wider way to remove leading and trailing CDATA stuff :

    title.trim().replace(/^(\/\/\s*)?$/g, '')
    

    It will also work if CDATA header and footer are commented.

提交回复
热议问题