# Регулярные выражения

Здесь описаны функции для работы с регулярными выражениями.

* [FindFirstRegExp( str src, str re ) arr.str](/stdlib/regexp.md#findfirstregexp-str-src-str-re-arr-str)
* [FindRegExp( str src, str re ) arr.arr.str](/stdlib/regexp.md#findregexp-str-src-str-re-arr-arr-str)
* [Match( str s, str re ) bool](/stdlib/regexp.md#match-str-s-str-re-bool)
* [RegExp( str src, str re ) str](/stdlib/regexp.md#regexp-str-src-str-re-str)
* [ReplaceRegExp( str src, str re, str repl ) str](/stdlib/regexp.md#replaceregexp-str-src-str-re-str-repl-str)

## Функции

### FindFirstRegExp(str src, str re) arr.str

Функция *FindFirstRegExp* находит первое вхождение регулярного выражения *re* в указанной строке *src*. Функция возвращает массив строк. Первый элемент содержит подстроку совпадающую с регулярным выражением, остальные элементы содержат значения групп **(...)**, если они определены в регулярном выражении.

```go
arr.str a &= FindFirstRegExp(`This45i33s a isi777s inis1i2sg`, `is(\d*)i(\d+)s`)
// a = {`is45i33s`, `45`, `33`}
```

### FindRegExp(str src, str re) arr.arr.str

Функция *FindRegExp* находит все вхождения регулярного выражения *re* в указанной строке *src*. Функция возвращает массив массивов. Первый элемент в каждом из массивов содержит подстроку совпадающую с регулярным выражением.

```go
arr.arr.str a &= FindRegExp(`My email is xyz@example.com`, `(\w+)@(\w+)\.(\w+)`)
// a = { { `xyz@example.com`, `xyz`, `example`, `com`} }
a &= FindRegExp(`This is a test string`, `i.`)
// a = { { `is` }, {`is`}, {`in`} }
```

### Match(str s, str re) bool

Функция *Match* определяет содержит ли данная строка вхождение указанного регулярного выражения.

```go
bool a = Match(`somethiabng striabnbg`, `a.b`)  // false
a = Match(`somethianbg string`, `a.b`) // true
```

### RegExp(str src, str re) str

Функция *RegExp* возвращает первое вхождение регулярного выражения *re* в указанной строке *src*. Если соответствия не найдено, то возвращается пустая строка.

```go
  str input = "This is a string тестовое значение"
  ret = RegExp(input, `is (.{2})`) + RegExp(input, `е(.+?)е`)
  // isстово
```

### ReplaceRegExp(str src, str re, str repl) str

Функция *ReplaceRegExp* находит все вхождения регулярного выражения *re* в указанной строке *src* и заменяет их на строку *repl*. В параметре *repl* можно указывать *$i* или *${i}* для i-го подсовпадения.

```go
str s = ReplaceRegExp("This is a string", `i(.{2})`, "xyz") 
// Thxyzxyza strxyz
s = ReplaceRegExp(" email is xyz@example.com", `(\w+)@(\w+)\.(\w+)`, "${3}.${2}@zzz")
// email is com.example@zzz
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ru.gentee.org/stdlib/regexp.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
