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(/
$/g, '
').replace(new RegExp('\b(' + matchWords.join('|') + ')\b','g'), '<mark>$&</mark>');
console.log(text);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…