Skip to content

Latest commit

 

History

History
80 lines (66 loc) · 2.49 KB

File metadata and controls

80 lines (66 loc) · 2.49 KB
title ms.custom ms.date ms.prod ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic f1_keywords dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
search Method (String) (JavaScript) | Microsoft Docs
01/18/2017
windows-client-threshold
devlang-javascript
language-reference
search
JavaScript
TypeScript
DHTML
search method
1cae0fbc-3319-4327-ba4e-d5fa2c4a9ba0
15
mikejo5000
mikejo
ghogen

search Method (String) (JavaScript)

Finds the first substring match in a regular expression search.

Syntax

  
stringObj.search(rgExp)   

Parameters

stringObj
Required. The String object or string literal on which to perform the search.

rgExp
Required. An instance of a Regular Expression object containing the regular expression pattern and applicable flags.

Return Value

If a match is found, the search method returns an integer value that indicates the offset from the beginning of the string where the first match occurred. If no match is found, it returns -1.

Remarks

You can also set the i flag that causes the search to be case-insensitive.

Example

The following example illustrates the use of the search method.

var src = "is but a Dream within a dream";  
var re = /dream/;  
var pos = src.search(re);  
document.write(pos);  
document.write("<br/>");  
  
re = /dream/i;  
pos = src.search(re);  
document.write(pos);  
  
// Output:   
// 24   
// 9  

Requirements

[!INCLUDEjsv3]

Applies To: String Object

See Also

exec Method (Regular Expression)
match Method (String)
Regular Expression Object
Regular Expression Syntax (JavaScript)
replace Method (String)
test Method (Regular Expression)
Regular Expression Programming (JavaScript)