In order to locate sentences that might include a series of stopwords mixed within the phrase to_match
, such as:
- 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 am able to only identify make wish
by utilizing this regex:
const regex = new RegExp(`(?:\\b)$to_match(?:\\b)`, "gi");
I am curious if there is a way to achieve 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)`;
Where any(stopword)
represents a method to match any stopword within the stopword list.
This regex should be capable of functioning regardless of the length of to_match_splitted
, including one or multiple stopwords appearing between each string within the list.