9 examples of 'javascript str_replace' in JavaScript

Every line of 'javascript str_replace' 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
this disclaimer
43function replaceAll(str) {
44 if (str != null){
45 str = str.replace(/\n\t/ig, "<br />");
46 }
47 return str;
48}
Important

Use secure code every time

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

507export function replaceAll(str, find, replace) {
508 return str.replace(new RegExp(find, "g"), replace);
509}
92export function replace(str, regexp){
93
94 for(let i = 0, len = regexp.length; i < len; i += 2){
95
96 str = str.replace(regexp[i], regexp[i + 1]);
97
98 if(!str){
99
100 break;
101 }
102 }
103
104 return str;
105}
62function replaceString(pString,pSearch,pReplace)
63// replaces in the string "pString" multiple substrings "pSearch" by "pReplace"
64{
65 //alert("cstring.js - replaceString() "+pString);
66 if (!pString) {
67 alert("replaceString()-Call - pString not defined!");
68 } else if (pString != '') {
69 {
70 //alert("cstring.js - replaceString() "+pString);
71 var vHelpString = '';
72 var vN = pString.indexOf(pSearch);
73 var vReturnString = '';
74 while (vN >= 0)
75 {
76 if (vN > 0)
77 vReturnString += pString.substring(0, vN);
78 vReturnString += pReplace;
79 if (vN + pSearch.length < pString.length) {
80 pString = pString.substring(vN+pSearch.length, pString.length);
81 } else {
82 pString = ''
83 }
84 vN = pString.indexOf(pSearch);
85 };
86 };
87 return vReturnString + pString;
88 }
89
90};
103function replaceAll(string, find, replace){
104 return string.replace(new RegExp(find.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), replace);
105}
212export function replaceAll(target: string, strToFind: string, replaceWith: string, ignoreCase = false): string {
213 var flags = "g"; //global match
214 if (ignoreCase === true) {
215 flags += "i";
216 }
217
218 return target.replace(RegExp(escapeRegExp(strToFind), flags), replaceWith);
219
220}
202function replaceAll(target, strToFind, replaceWith, ignoreCase = false) {
203 var flags = "g"; //global match
204 if (ignoreCase === true) {
205 flags += "i";
206 }
207 return target.replace(RegExp(escapeRegExp(strToFind), flags), replaceWith);
208}
20function replaceAll (input, find, replace) {
21 let regex = new RegExp(find, 'g');
22 return input.toString().replace(regex, replace);
23};
339export function replace(str, search, replace) {
340 return str.replace(new RegExp(escape(search), "g"), replace);
341}

Related snippets