RegEx for matching MongoDB strings RegEx for matching MongoDB strings mongoose mongoose

RegEx for matching MongoDB strings


Your regular expression should be

for (let i = 0; i < arrayOfActors.length; i++) {  arrayOfqueries.push(new RegExpr("\b" + arrayOfActors[i] + "\b"))}


I'm guessing that a simple capturing group might suffice here. Then, based on Fanpark solution, your code might look like:

for (let i = 0; i < arrayOfActors.length; i++) {  arrayOfqueries.push(new RegExpr("(" + arrayOfActors[i] + ")"))}

If that did not work, we can try other expressions such as:

(?:[\s\S]*)(David Prowse)(?:[\s\S]*)

and our code might look like:

arrayOfqueries.push(new RegExpr("(?:[\s\S]*)(" + arrayOfActors[i] + ")(?:[\s\S]*)"))

Also, metachars should be escaped.

DEMO