3 examples of 'find special characters in string' in JavaScript

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.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
1export function escapeSpecialChars(str) {
2 return str
3 .replace(/&/g, "&")
4 .replace(//g, ">")
5 .replace(/"/g, """)
6 .replace(/'/g, "'");
7}
140function 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}
11function filterControlCharacters(string) {
12 if(string) {
13 return string.replace(/[\x00-\x1F\x7F-\x9F]/g, '');
14 }
15}

Related snippets