Reputation: 117
I need to remove all the portion of text in square braces along with the braces, in TypeScript. How can I do this?
var text="All-Weather Floor Liner Package [installed_msrp]"
Upvotes: 0
Views: 63
Reputation: 2732
Try this, hope it helps
var text="All-Weather Floor Liner Package [installed_msrp]"
alert(text.replace(/\s*\[.*?\]\s*/g, ''));
This will also remove excess whitespace before and after the parentheses
Thanks
Upvotes: 1
Reputation: 7975
You can use the javascript function 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 "
Upvotes: 1
Reputation: 1424
You may use a RegExp in conjucation with the replace function. Like this:
'All-Weather Floor Liner Package [installed_msrp]'.replace(/\[.*\]/g, '');
Upvotes: 0