Regular expressions in JavaScript

xiaoxiao2021-03-06  58

Search method

Returns the location of the first sub-string that matches the regular expression lookup content.

Stringobj.Search (RGEXP)

parameter

StringObj

required. To find the String object or string text of the lookup.

RGEXP

required. A regular expression object containing regular expression modes and available flags.

Description

Search methods indicate whether there is a corresponding match. If a match is found, the Search method will return an integer value indicating that the offset position started by this matching range string. Returns -1 if no match is found.

Example

The following example demonstrates the usage of the Search method.

Function searchdemo () {

Var r, re; // declared variables.

Var s = "The rain in spain falls mainly in the place.";

RE = / falls / i; // Create regular expression mode.

r = s.search (re); / / Find strings.

Return (R); // Returns the Boolean result.

}

转载请注明原文地址:https://www.9cbs.com/read-111815.html

New Post(0)