How can I remove specific special characters from a string using regex in JavaScript?
- single quotes
' - double quotes
" - ampersand
& - registered
® - trademark
™
How can I remove specific special characters from a string using regex in JavaScript?
'"&®™Use the string.replace() method and the unicode escape codes for your special characters. You have to use the \ character to escape in JavaScript regex
var str = 'Here is a \' string \" with \" \' some @ special ® characters ™ & &'
str.replace(/['"\u0040\u0026\u2122\u00ae]/g, '')
/pattern/ denotes a regex pattern in JavaScript
[charset] says which set of characters to match
/g specifies global matches so it will replace all occurrences