search (RegExp - JavaScript)

Gets the index of the first occurrence of a substring.

Defined in

RegExp (Standard - JavaScript)

Syntax

search(searchString:string) : int
Parameters Description
searchString The string to be searched.
Return value Description
int The index of the first occurrence of the regular expression, or -1 if the search fails.

Usage

This RegExp object defines the search criteria.

Examples

This example searches for the string moscow case-insensitive.
var cities = new String("Paris   Moscow   Tokyo");
var regexp = /(moscow)/i;
if (regexp.search(cities) > 0)
{
	return "Found: " + regexp.toString();
} else {
	return "Not found: " + regexp.toString();
}