match substring in javascript code example
Example 1: check for substring javascript
const string = "javascript";
const substring = "script";
console.log(string.includes(substring));
Example 2: js check if string contains character
"FooBar".includes("oo");
"FooBar".includes("foo");
"FooBar".includes("oo", 2);
Example 3: match substring js
const string = "foo";
const substring = "oo";
console.log(string.includes(substring));
Example 4: javascript regex example match
let reg = /abc/
reg = new RegExp('abc')
let str = 'Abc abc abc'
str.match(/abc/)
str.match(/abc/g)
str.match(/abc/i)
str.match(/abc/ig)
str.match('abc', 'ig')
Example 5: js check if string contains character
if (your_string.indexOf('hello') > -1)
{
alert("hello found inside your_string");
}