πΒ 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?"