伙计们。我有一个包含很多特殊字符的特定字符串,我需要将其删除。
这是字符串:
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 </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>'
const result = str.replace(/<.+?>/g,'')
console.log(result)
关于javascript - 使用正则表达式删除特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58598406/