📌  相关文章
📜  js 检查字符串是否包含来自数组 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:00.298000             🧑  作者: Mango

代码示例6
function buildSearch(substrings) {
  return new RegExp(
    substrings
    .map(function (s) {return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');})
    .join('{1,}|') + '{1,}'
  );
}


var pattern = buildSearch(['hello','world']);

console.log(pattern.test('hello there'));
console.log(pattern.test('what a wonderful world'));
console.log(pattern.test('my name is ...'));