const str = 'hello world!';
const result = /^hello/.test(str);
console.log(result); // true/**
The test() method executes a search for a match between
a regular expression and a specified string
*/
JavaScript | RegExp test() Method
The RegExp test() Method in JavaScript is used to test for match in a string. If there is a match this method returns trueelse it returns false.
Syntax:
RegExpObject.test(str)
Where str is the stringto be searched. This is required field.