/\ba/.exec("abc");
/c\b/.exec("abc");
/\B /.exec(" abc");
/ \B/.exec("abc ");Word boundary assertion: \b, \B / notebook
Word boundary assertion: \b, \B
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
function hasThanks(str) {
return /\b(thanks|thank you)\b/i.test(str);
}
hasThanks("Thanks! You helped me a lot."); // true
hasThanks("Just want to say thank you for all your work."); // true
hasThanks("Thanksgiving is around the corner."); // false