if (searchText.length > 3) {
regex = new RegExp("(\\W)" + searchText, 'gi');
}
else {
regex = new RegExp("(\\W)\b" + searchText + '\b', 'gi');}
}
Obviously, I've wrapped this wrong, but if I wanted to match only whole words when the search term is 1, 2, or 3 characters, what would the correct syntax be?
e.g. "do" won't match the do in "DOne" but "heat" would match the heat in "HEATed"