Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- someString = 'the cat looks like a cat'
- anotherString = someString.replace('cat', 'dog');
- someString = 'the cat looks like a cat';
- anotherString = someString.replace(/cat/g, 'dog');
- // anotherString now contains "the dog looks like a dog"
- anotherString = someString.replace(/cat/g, 'dog');
- function multiReplace(str, match, repl) {
- do {
- str = str.replace(match, repl);
- } while(str.indexOf(match) !== -1);
- return str;
- }
- multiReplace("the cat looks like a cat", "cat", "dog"); // "the dog looks like a dog"
Add Comment
Please, Sign In to add comment