English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
search()The method performs a search between the regular expression and the string match.
If a match is found, it will return the position of the first match. If no match is found, it will return-1.
You can find it inRegExp tutorialandRegExp object referenceLearn more about regular expressions.
string.search(regex)
var str = 'The question is to be, or not to be, that is to be.39 var pos = str.search('to be');Test and see‹/›
All browsers fully support the search() method:
Method | |||||
search() | Is | Is | Is | Is | Is |
Parameter | Description |
---|---|
regex | Regular Expression. If a string is passed, it is implicitly converted to a regular expression |
Return value: | The index of the first match between the regular expression and the given string; if not found, then-1 |
---|---|
JavaScript Version: | ECMAScript 1 |
The following examples demonstratei
Usage of Modifiers (case-insensitive):
var str = 'The question is TO BE, or not to be, that is to be.' var pos = str.search(/to be/i);Test and see‹/›