Logo

Programming-Idioms

History of Idiom 63 > diff from v43 to v44

Edit summary for version 44 by programming-idioms.org:
[JS] Revert nonsense

Version 43

2019-10-16, 12:13:23

Version 44

2019-10-16, 12:14:05

Idiom #63 Replace fragment of a string

Assign to x2 the value of string x with all occurrences of y replaced by z.
Assume occurrences of y are not overlapping.

Idiom #63 Replace fragment of a string

Assign to x2 the value of string x with all occurrences of y replaced by z.
Assume occurrences of y are not overlapping.

Extra Keywords
substring substitute
Extra Keywords
substring substitute
Code
var x2 = x.replace(new RegExp(y, 'g'), z); "><marquee>
Code
var x2 = x.replace(new RegExp(y, 'g'), z);
Comments bubble
This works well only if y doesn't contain special regexp characters.
Comments bubble
This works well only if y doesn't contain special regexp characters.
Doc URL
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
Doc URL
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
Origin
https://stackoverflow.com/a/17606289/871134
Origin
https://stackoverflow.com/a/17606289/871134