伙计们。我有一个包含很多特殊字符的特定字符串,需要删除。
这是字符串:
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,'')
任何帮助都会很棒!谢谢
答案 0 :(得分:3)
您正在尝试剥离转义的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)