JavaScript RegEx test() method

The JavaScript RegExp test() method is used to search for a match between a regular expression and a specified string.

Syntax:

RegExpObject.test(string);

Parameters: string: It represents the string to be searched.

Return: It returns true if the match between a regular expression and a specified string is found otherwise returns false.

Example:

<!DOCTYPE html>
<html>
<body>
<script>
var string = "HELLO WORLD";
var a = new RegExp( "HELLO", "g" );
var print = a.test(string);
document.write("Returned value : " + print);
</script>
</body>
</html>
Please follow and like us:
Content Protection by DMCA.com