Last active
January 31, 2017 08:43
-
-
Save codeorelse/28c115ff568252bc1a4a3684d50630b2 to your computer and use it in GitHub Desktop.
Break word instances to seperate words
This file contains 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
var breakWordsIntoTwoWords = function(sentenceContainingWord, word) { | |
var regex = /hypotheek([^ ][-a-z]*)/gi; | |
while ((m = regex.exec(sentenceContainingWord)) !== null) { | |
if (m.index === regex.lastIndex) { | |
regex.lastIndex++; | |
} | |
// The result can be accessed through the `m`-variable. | |
var firstLetterCapital = word.substr(0,1).toUpperCase(); | |
var searchForWord = m[0].substr(0,1) === firstLetterCapital ? firstLetterCapital + word.substr(1) : firstLetterCapital.toLowerCase() + word.substr(1); | |
sentenceContainingWord = sentenceContainingWord.replace(m[0], searchForWord + ' ' + m[0].split(searchForWord)[1]); | |
} | |
return sentenceContainingWord; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment