gpt4 book ai didi

javascript - 使用正则表达式删除特殊字符

转载 作者:行者123 更新时间:2023-11-30 10:59:13 25 4
gpt4 key购买 nike

伙计们。我有一个包含很多特殊字符的特定字符串,我需要将其删除。

这是字符串:

let str = 'The start tag must have a matching end tag.  An explicit end tag can be provided by adding </cfscript>.If the body of the tag is empty, you can use the shortcut <cfscript .../>.<p>The CFML compiler was processing:<ul><li>A cfscript tag beginning on line 90, column 10.<li>A cfscript tag beginning on line 90, column 10.</ul>'

这是我的正则表达式,它不起作用:var regex = str.replace(/<|>|\/|\/ul|\/li|ul&|li&/g,'')

任何帮助都会很棒!谢谢

最佳答案

您正在尝试去除转义的 HTML 标签(< 是 <;并且 > 是 >),以及它们之间的所有内容(参见 regex101 ) :

const str = 'The start tag must have a matching end tag.  An explicit end tag can be provided by adding &lt;/cfscript&gt;.If the body of the tag is empty, you can use the shortcut &lt;cfscript .../&gt;.&lt;p&gt;The CFML compiler was processing:&lt;ul&gt;&lt;li&gt;A cfscript tag beginning on line 90, column 10.&lt;li&gt;A cfscript tag beginning on line 90, column 10.&lt;/ul&gt;'

const result = str.replace(/&lt;.+?&gt;/g,'')

console.log(result)

关于javascript - 使用正则表达式删除特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58598406/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com