Javascript Regex Test

javascript-regex

regexObj.test(str)

The test() method executes a search for a match between a regular expression and 
a specified string. Returns true or false.

Use test() whenever you want to know whether a pattern is found in a string 
(similar to the String.prototype.search() method, difference is that test 
returns a boolean, whilst search returns the index (if found) or -1 if not 
found); for more information (but slower execution) use the exec() method 
(similar to the String.prototype.match() method). As with exec() (or in 
combination with it), test() called multiple times on the same global regular 
expression instance will advance past the previous match.

var str = "hello world!";
var result = /^hello/.test(str);
console.log(result); // true
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License