我有一个大字符串(1000 个单词),我想将其与数组的所有元素进行比较,该数组也包含大字符串,以获取所有 3 个或更多连续单词匹配。我已经用正则表达式实现了它,但得到了空白匹配数组。
较小文本的示例:
let textToCompare = "Hello there how are you doing with your life";
let textsToCompareWith= [
{ id:1, text:"Hope you are doing good with your life" },
{ id:2, text:"what are you doing with your life. hello there how are you" },
{ id:3, text:"hello there mate" }
];
Run Code Online (Sandbox Code Playgroud)
预期输出:
[
{id:1, matchedText:["with your life"]},
{id:2, matchedText:["are you doing with your life","hello there how are you"]},
{id:3, matchedText:[]}
];
Run Code Online (Sandbox Code Playgroud)
电流输出:
[
{id:1, matchedText:[]},
{id:2, matchedText:[]},
{id:3, …Run Code Online (Sandbox Code Playgroud)