I have to build a RegExp obejct, that will search words from an array, and will find only whole words match.
e.g. I have a words array ('יל','ילד'), and I want the RegExp to find 'a' or 'יל' or 'ילד', but not 'ילדד'.
This is my code:
var text = 'ילד ילדדד יל';
var matchWords = ['יל','ילד'];
text = text.replace(/\n$/g, '\n\n').replace(new RegExp('\\b(' + matchWords.join('|') + ')\\b','g'), '<mark>$&</mark>');
console.log(text);
What I have tried:
I tried this code:
new RegExp('(יל|ילד)','g');
It works well, but it find also words like "ילדדדד", I have to match only the whole words.
I tried also this code:
new RegExp('\\b(יל|ילד)\\b','g');
but this regular expression doesn't find any word!
How should I build my RegExp?