The goal is to find all sentences that may contain a list of stopwords in between the phrase to_match like these:
- make wish
- make a wish
- make the a wish
let stopword: string[]= ["of", "the", "a"];
let to_match : string = "make wish";
let text: string = "make wish wish make a wish wish wish make the a wish make";
I can only match make wish using this regex:
const regex = new RegExp(`(?:\\b)$to_match(?:\\b)`, "gi");
I'm wondering if it's possible to do something like
let to_match_splitted: string[] = to_match.split(" ");
const regex = `(?:\\b)${to_match_splitted[0]}\s(${any(stopword)}?)+\s${to_match_splited[1]}(?:\\b)`;
With any(stopword) being something that match any stopword in stopword list.
And having a regex that works whatever is the length of the to_match_splitted with one or many stopwords between each string in the list.