Last active
October 6, 2019 00:17
-
-
Save hyvyys/55e078f4d083f04dbb15dec2aacda8ab to your computer and use it in GitHub Desktop.
Syllable regular expression (English)
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
function syllableRegex() { | |
const consonants = "[bcdfghjklmnpqrstvwxyz']"; | |
const vowels = "[aeiouy]"; | |
const separators = "[ \\.,:;!?]|$"; | |
const wordSep = `(?=${separators})`; | |
const wordSepOrConsonant = `(?=${separators}|${consonants})`; | |
return new RegExp( | |
`${consonants}*${vowels}{1,3}` + | |
`(${consonants}*e${wordSep}|${consonants}*${wordSepOrConsonant})`, | |
"ig" | |
); | |
} | |
/* should give something like (unescaped): | |
/[bcdfghjklmnpqrstvwxyz']*[aeiouy]{1,3}([bcdfghjklmnpqrstvwxyz']*e(?=[ ,.:'!?]|$)|[bcdfghjklmnpqrstvwxyz']*(?=[ ,.:'!?]|[bcdfghjklmnpqrstvwxyz']|$))/gi; | |
*/ | |
export default syllableRegex(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment