我需要使用通配符正则表达式过滤字符串数组:
// my search key
var myKeyword = 'bar';
// my search list
var strings = ['foo', 'bar', 'foobar', 'barfoo', 'hello', 'java', 'script', 'javascript'];
// my results
var results = [];
// the regexp, I don't understand
var regex = new RegExp(\*/, myKeyword);
// the for loop
for (var i = 0; i < strings.length; i++) {
if (regex.test(strings[i]) {
results.push(strings[i]);
}
}
console.log(results); // prints ['bar', 'foobar', 'barfoo']
那么如何修复正则表达式?