88 of 264 menu

search method

The search method finds string matches with regular expression and returns the position of the first match. If no matches are found, then the method will return -1.

Syntax

string.search(regular expression);

Example

Let's find the position of a substring:

let str = 'aaa xax bbb'; let res = str.search(/x.x/); console.log(res);

The code execution result:

4

See also

  • the test method
    that checks a string
  • the match method
    that searches for matches in a string
  • the matchAll method
    that searches for all matches in a string
  • the exec method
    that performs a sequential search
  • the replace method
    that performs search and replacement
  • the split method
    that splits a string
  • the includes method
    that searches for a given string in the current string
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline