删除一部分文本

Removing a portion of text

本文关键字:文本 一部分 删除      更新时间:2023-09-26

在TypeScript中,我需要删除所有用大括号括起来的文本部分。我该怎么做呢?

var text="All-Weather Floor Liner Package [installed_msrp]"

试一下,希望能有所帮助

var text="All-Weather Floor Liner Package [installed_msrp]"
alert(text.replace(/'s*'[.*?']'s*/g, ''));

这也将删除括号

前后多余的空格。

JSFIDDLE

谢谢

您可以使用javascript函数string.replace

var text="All-Weather Floor Liner Package [installed_msrp]"
var myCleanedStr = text.replace(/('[.*'])/g, "");
console.log(myCleanedStr); // Output is "All-Weather Floor Liner Package " 

您可以将RegExp与replace函数结合使用。这样的:

'All-Weather Floor Liner Package [installed_msrp]'.replace(/'[.*']/g, '');