Skip to content

Instantly share code, notes, and snippets.

@jarble
Last active May 1, 2021 21:02
Show Gist options
  • Save jarble/88bbca5ca291abae540e0c610aae265d to your computer and use it in GitHub Desktop.
Save jarble/88bbca5ca291abae540e0c610aae265d to your computer and use it in GitHub Desktop.
const replaceOnce = require('replace-once');
var str = 'I have a cat, a cathy, and a catch.';
var find = ['cat', 'cathy', 'catch'];
var replace = ['catch', 'catch', 'cathy'];
console.log(replaceOnce(str, find, replace, 'gi'));
//=> 'I have a catch, a catchhy, and a catchch.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment