πΒ Reference
replaceAll()
λ©μλλ ν¨ν΄μ λͺ¨λ μΌμΉ νλͺ©μ΄ κ΅μ²΄λ‘ λ체λ μ λ¬Έμμ΄μ λ°ννλ€.RegExp
μΌ μ μμΌλ©° λ체λ κ° μΌμΉμ λν΄ νΈμΆ ν λ¬Έμμ΄ λλ ν¨μμΌ μ μλ€.replaceAll(regexp, newSubstr)
replaceAll(regexp, replacerFunction)
replaceAll(substr, newSubstr)
replaceAll(substr, replacerFunction)
Parameters
regexp (pattern)
RegExp
κ°μ²΄ λλ 리ν°λ΄μ΄λ€.newSubstr
λλ μ§μ λ replacerFunction
μμ λ°ν λ κ°μΌλ‘ λ체λλ€.RegExp
λ TypeError
λ₯Ό λ°μμν¨λ€. : "replaceAll
μ μ μ RegExp
λ‘ νΈμΆλμ΄μΌ νλ€".substr
newSubstr
λ‘ λ체 λ λ¬Έμμ΄μ΄λ€.newSubstr (replacement)
regexp
λλ substr
λ§€κ° λ³μλ‘ μ§μ λ νμ λ¬Έμμ΄μ λ체νλ λ¬Έμμ΄μ΄λ€.replacerFunction (replacement)
regexp
λλ substr
μ λν μΌμΉ νλͺ©μ λ체νλ λ° μ¬μ©ν μ νμ λ¬Έμμ΄μ μμ±νκΈ° μν΄ νΈμΆ ν ν¨μμ΄λ€.Return
const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';
console.log(p.replaceAll('dog', 'monkey'));
// expected output: "The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?"
// global flag required when calling replaceAll with regex
const regex = /Dog/ig;
console.log(p.replaceAll(regex, 'ferret'));
// expected output: "The quick brown fox jumps over the lazy ferret. If the ferret reacted, was it really lazy?"