Last active
June 3, 2018 19:25
-
-
Save christiannaths/c25635c493e610316dd70718ff95a3b1 to your computer and use it in GitHub Desktop.
Split a template literal at word boundry
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 w() { | |
arguments[0] = { raw: arguments[0] }; | |
const str = String.raw(...arguments); | |
return str.match(/\b(\w+)\b/gm); | |
} | |
w`this is a string of words` | |
// => ["this", "is", "a", "string", "of", "words"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment