Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsFor a plain substring check, use JavaScript’s String.prototype.includes()—jQuery is not needed. If you mean a complete, standalone word rather than characters that happen to appear inside a longer word, use a regular expression instead. The distinction matters: searching for cat with includes() also matches catalog.
Check whether a string contains a substring
includes() returns true when the search string appears anywhere in the text, and false otherwise:
const text = "The quick brown fox.";
const word = "fox";
const found = text.includes(word); // true
This is case-sensitive, so "Fox" does not match "fox". To perform a basic case-insensitive substring search, convert both strings to the same case first:
const found = text.toLowerCase().includes(word.toLowerCase());
includes() takes a string search value, not a regular expression; passing a regex causes a TypeError. Also decide how your application should handle an empty search string: text.includes("") returns true. These behaviors are documented in MDN’s JavaScript String.prototype.includes() reference.
#1 Best Overall
Check for a complete word
Use a regular expression with word-boundary assertions when you want a basic whole-word match. Escape the search term first so punctuation supplied as input is treated literally, not as regex syntax:
function escapeRegExp(value) {
return value.replace(/[.*+?^${}()|[]\]/g, "\$&");
}
function containsWholeWord(text, word) {
if (!word) return false;
return new RegExp(`\b${escapeRegExp(word)}\b`, "i").test(text);
}
containsWholeWord("A fox crossed the road.", "fox"); // true
containsWholeWord("A fox crossed the road.", "Fox"); // true
containsWholeWord("A fox crossed the road.", "ox"); // false
The i flag makes this example case-insensitive. The empty-string check is an explicit choice for this helper; without it, the expression would not represent a meaningful requested word.
Rank #2
JavaScript’s b uses regex word-character rules, not every language’s idea of a word. In ordinary use, letters, digits, and underscores count as word characters, while punctuation such as an apostrophe can create a boundary that may not match how readers parse a word. MDN explains these word-boundary rules and notes that languages whose words are not separated by spaces, including Chinese and Thai, may need more advanced segmentation such as Intl.Segmenter. If your text has specialized tokenization or Unicode requirements, define and test the desired boundary behavior with representative examples.
When jQuery selectors apply
jQuery is useful for selecting elements in a document, but it is not needed to search an arbitrary JavaScript string. The jQuery [attr~="value"] selector checks for a space-delimited word in an HTML attribute; it is not a general string-search method. The jQuery selector documentation describes selectors, and the jQuery() reference covers querying DOM elements. For a standalone string variable, use includes() or a regular expression as appropriate.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Quick Recap
Best Value
Rank #4
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




