Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function replaceWord(str, before, after)
- {
- var re = new RegExp(before, 'gi');
- after = (before[0].toUpperCase() == before[0] ? after = after[0].toUpperCase() + after.slice(1) : after);//if first letter of before is capitalized, it'll change after to capitalized as well.
- str = str.replace(re, after);
- return str;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement