test (JavaScript)

Tests a string for a match of a regular expression.

Defined in

RegExp (Standard - JavaScript)

Syntax

test(string:string) : boolean
Parameters Description
string The string to be tested.
Return value Description
boolean True if the string contains a match for the regular expression; false otherwise.

Examples

This example returns true because the string contains Moscow.
var re = new RegExp("(Moscow)|(Tokyo)");
if(re.test("The city of interest is Moscow.")) {
	requestScope.z = "String has match for " + re.valueOf();
} else {
	requestScope.z = "String does not have match for " + re.valueOf();
}