10 examples of 'jquery replace all occurrences of a string' in JavaScript

Every line of 'jquery replace all occurrences of a 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
this disclaimer
88replace: function replace(aString) {
89 if (!aString) return aString;
90 this.substitutions.forEach(function(element) { aString = element.replace(aString); });
91 return aString;
92},
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

102function replaceString(s, x) {
103 return x.replace(new RegExp("\\\\" + s, "g"), "\\$&").replace(/\n/g, "$&" + spaces(indent) + " ")
104}
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};
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}
43function replaceAll(str) {
44 if (str != null){
45 str = str.replace(/\n\t/ig, "<br />");
46 }
47 return str;
48}
224function replace(regexp, newstring) {
225 results = results.replace(regexp, newstring);
226 }
14export function replace (text: string, start: number, len: number, str: string): string {
15 if (!text)
16 return str;
17 return [text.slice(0, start), str, text.slice(start + len)].join('');
18}
103function replaceAll(string, find, replace){
104 return string.replace(new RegExp(find.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), replace);
105}
1function __TS__StringReplace(
2 this: void,
3 source: string,
4 searchValue: string,
5 replaceValue: string | ((substring: string) => string)
6): string {
7 [searchValue] = string.gsub(searchValue, "[%%%(%)%.%+%-%*%?%[%^%$]", "%%%1");
8
9 if (typeof replaceValue === "string") {
10 [replaceValue] = string.gsub(replaceValue, "[%%%(%)%.%+%-%*%?%[%^%$]", "%%%1");
11 const [result] = string.gsub(source, searchValue, replaceValue, 1);
12 return result;
13 } else {
14 const [result] = string.gsub(
15 source,
16 searchValue,
17 match => (replaceValue as (substring: string) => string)(match),
18 1
19 );
20 return result;
21 }
22}
10export function replaceSubstring(str, start, end, replacer) {
11 const prefix = str.substring(0, start);
12 let suffix = str.substring(end + 1);
13
14 // Ensure suffix starts with a SPACE,
15 // caret will be on the same line after replacing
16 if (suffix[0] !== ' ') {
17 suffix = ` ${suffix}`;
18 }
19
20 const prefixAndContent = `${prefix}${replacer}`;
21
22 return {
23 value: `${prefixAndContent}${suffix}`,
24 caret: prefixAndContent.length + 1,
25 };
26}

Related snippets