# search method in JavaScript regular expressions

In this lesson, we will analyze the `search` method, which searches a string using a regular expression. It receives the following parameters:

`string.search(regex)`

The method returns the position of the first found substring, and if it is not found, then `-1`.

In the following example, we find a position of the substring `'aaa'` in our string:

`let str = 'a aa aaa aaaa aaaa'; let res = str.search(/aaa/);`

As a result, the following will be written to the variable:

`5`

Given a string:

`let str = '1 23 456 789';`

Find a position of the first number that has three digits.

← →
↑
en ru