Created
July 24, 2017 17:20
-
-
Save kodie/ea8c92855def4572a21fff01ada618fc to your computer and use it in GitHub Desktop.
A recursive, case-insensitive, keyword matcher.
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 matches(str, kw) { | |
var m = []; | |
if (kw.constructor !== Array) { kw = [kw]; } | |
for (var i = 0; i < kw.length; i++) { | |
var f = str.match(new RegExp(kw[i], 'gi')); | |
if (f) { m = m.concat(f); } | |
} | |
return m; | |
} | |
matches('I love Christmas!', ['christ', 'christmas']); | |
//[ 'Christ', 'Christmas' ] | |
matches('Poopoo Face', 'poo'); | |
//[ 'Poo', 'poo' ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment