Every line of 'find special characters in string' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
1 export function escapeSpecialChars(str) { 2 return str 3 .replace(/&/g, "&") 4 .replace(/</g, "<") 5 .replace(/>/g, ">") 6 .replace(/"/g, """) 7 .replace(/'/g, "'"); 8 }
Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code
140 function SpecialCharDecode(s) { 141 var tagsToReplace = { 142 '<': '<', 143 '>': '>', 144 '[': '[', 145 ']': ']', 146 '"': '"' 147 }; 148 149 return s.replace(/<|>|[|]|"/g, function (tag) { 150 return tagsToReplace[tag] || tag; 151 }); 152 //return s.replace(/\[/g, "[").replace(/\]/g, "]").replace(/\"/g, "'"); 153 //return s.replace(/[\u00A0-\u9999<>\&]/gim, function(i) { return '&#'+i.charCodeAt(0)+';'; }); 154 }
11 function filterControlCharacters(string) { 12 if(string) { 13 return string.replace(/[\x00-\x1F\x7F-\x9F]/g, ''); 14 } 15 }