my regex is dynamically constructed by using this code in javscript :
var regExp = new RegExp("\\b" + $("#value").val() + "\\b", "ig");
i.e the regex would be a simple \bbrother\b/ig and the problem is that it is also matching words such as
don in don't
sister in sister's
it should match word only if it is a whole word i.e
The don came late - match
don't do that - no match
she is my sister - match
my sister's wedding - no match
EDIT: Thanks for the answers.Please suggest the fastest (or least expensive) method(if this makes an impact) if the regex is very large like \bbrother|sister|car|truck.......\b to the tune of 6500 OR words.
There’s a few ways you can do it. I would recommend a forward negative lookahead.
\bbrother\b(?!')The construct
(?!something)ensures thatsomethingdoes not follow the match.