Written: August 22, 2026
Modern JavaScript makes substring checks easy with String.prototype.includes. Older code often used indexOf !== -1. Regex is for patterns, not for every simple contains check.
Examples
const text = "Appium parallel sessions";
console.log(text.includes("parallel")); // true
console.log(text.indexOf("Appium") !== -1); // true
console.log(/session/i.test(text)); // true (case-insensitive)
Gotchas
includes is case-sensitive. Normalize with toLowerCase() on both sides when you want a case-insensitive contains.
For user search boxes, trim input and decide whether empty query should match everything or nothing.
Keep learning
If this walkthrough on javascript string contains substring helped, open the code again and change one input or assumption. Small experiments beat rereading the same example.
Want more step-by-step tutorials like this? Browse blog.xqa.io — and tell us which topic you want next.