exec (JavaScript)

Executes a search using a regular expression.

Defined in

RegExp (Standard - JavaScript)

Syntax

exec(searchString:string) : string
Parameters Description
searchString The string to be searched.
Return value Description
string[] Substrings that match the regular expression, or null if the search fails.

Usage

This RegExp object defines the search criteria.

Examples

This example returns Moscow - Moscow.
var cities = new String("Paris   Moscow   Tokyo");
var regexp = /(Moscow)/;
var s = regexp.exec(cities);
if(s == null)
	return "No match";
else
	return s.join(" - ")