Skip to content

Instantly share code, notes, and snippets.

@Octagon-simon
Created July 1, 2022 20:58
Show Gist options
  • Select an option

  • Save Octagon-simon/ad3dd97a9298949fc2dde36751e8a1fc to your computer and use it in GitHub Desktop.

Select an option

Save Octagon-simon/ad3dd97a9298949fc2dde36751e8a1fc to your computer and use it in GitHub Desktop.
const search = (search, replace) => {
//the string
const str = "I love to eat banana and mango";
//replace all occurrences of the searched term
return str.replaceAll( new RegExp(search, 'gi'), replace );
}
//invoke the function
console.log( search('BANANA', '🍌') );
console.log( search('MANGO', '🥭') );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment