Last active
October 8, 2017 16:11
-
-
Save cdaz5/36c8db26ab676dcdcbbece434922f159 to your computer and use it in GitHub Desktop.
.replace blog post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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