I currently have an API that returns the following string inside parentheses
(Multivitamin Gummies - Berry, Peach & Orange - 150ct - Up&Up™)
I want it to be instead formatted to the user like so
(Multivitamin Gummies - Berry, Peach & Orange - 150ct - Up&Up)
Is there a way to dynamically do this fix this in javascript?
Here is another example:
(Aloe Hand Sanitizer Gel - 8 fl oz - Up&Up™)
should return
(Aloe Hand Sanitizer Gel - 8 fl oz - Up&Up)
I hope this helps
var str = 'Aloe Hand Sanitizer Gel - 8 fl oz - Up&Up™'; console.log(str.match(/[^™]+/)[0]);
Add the characters you want to replace in the or |
like below in the regex and replace using .replace()
/™|&|™/g
var str = 'Aloe Hand Sanitizer Gel - ™ 8 fl oz - Up&Up™'; console.log(str.replace(/™|&|™/g, ""));
Looks like you want to replace all Unicode with empty string.
You can use regex str.replace(/(&#\d+;)/g,"")
to remove these characters
var str = '(Multivitamin Gummies - Berry, Peach & Orange - 150ct - Up&Up™)'; console.log(str.replace(/(&#\d+;)/g,"")); str = '(Aloe Hand Sanitizer Gel - 8 fl oz - Up&Up™) '; console.log(str.replace(/(&#\d+;)/g,""));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.