javascript search() method


  Translation results:

English [sɜ:tʃ] US [sɜ:rtʃ]

##v. Search; search, search; investigate; explore

n. Search; investigate; explore

Third person singular: search Present participle: searching Past tense: search Past participle: search

javascript search() methodsyntax

Function: Used to retrieve a specified substring in a string, or retrieve a substring that matches a regular expression.

Syntax: stringObject.search(regexp)

Parameter: regexp This parameter can It is the substring that needs to be retrieved in stringObject, or it can be the RegExp object that needs to be retrieved. Note: To perform a case-ignoring search, append the flag i.

Returns: The starting position of the first substring matching regexp in stringObject.

Note: The search() method does not perform a global match, it will ignore the flag g. It also ignores the lastIndex property of the regexp and always retrieves from the beginning of the string, which means it always returns the first matching position of the stringObject.

Comments: If no matching substring is found, -1 is returned.

javascript search() methodexample

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script type="text/javascript">

    var str="Visit php.cn!"
    document.write(str.search(/php.cn/))

</script>

</body>
</html>

Run instance »

Click the "Run instance" button to view the online instance

Popular Recommendations

Home

Videos

Q&A