Skip to content

Instantly share code, notes, and snippets.

@cdaz5
Last active October 8, 2017 16:11
Show Gist options
  • Select an option

  • Save cdaz5/36c8db26ab676dcdcbbece434922f159 to your computer and use it in GitHub Desktop.

Select an option

Save cdaz5/36c8db26ab676dcdcbbece434922f159 to your computer and use it in GitHub Desktop.
.replace blog post
function cocknify(input) {
// Couple things involving Regex:
// 1. The \b matches a word boundary (in other words where a word character is not
// followed or preceded by another word character). This will match only words
// that start with 'h' and not touch any internal h's.
// 2. The h is our search value.
// 3. The g makes the search global rather than just repalcing the first h it comes
// across and returning (keep in mind the \b stops it from effecting any internal h's).
// 4. The i makes it case in-sensitive so 'H' and 'h' are replaced.
// 5. Lastly, the backslash before the backtick is needed to escape the quotes.
return input.replace(/\bh/gi, '\`')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment