Tests a string for a match of a regular expression.
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();
}