Skip to main content

JavaScript test() Method

  • var str = "The best things in life are free";
    var patt = new RegExp("e");
    var res = patt.test(str);
  • 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.
  • Back to code snippet queries related javascript