Skip to content

Instantly share code, notes, and snippets.

@kodie
Created July 24, 2017 17:20
Show Gist options
  • Save kodie/ea8c92855def4572a21fff01ada618fc to your computer and use it in GitHub Desktop.
Save kodie/ea8c92855def4572a21fff01ada618fc to your computer and use it in GitHub Desktop.
A recursive, case-insensitive, keyword matcher.
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