Skip to content

Commit 418ca73

Browse files
authored
9-regular-expressions/09-regexp-groups
1 parent d905dbe commit 418ca73

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

9-regular-expressions/09-regexp-groups/article.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
1-
# Capturing groups
1+
# Скобочные группы
22

3-
A part of a pattern can be enclosed in parentheses `pattern:(...)`. This is called a "capturing group".
3+
Часть шаблона можно заключить в скобки `pattern:(...)`. Это называется "скобочная группа".
44

5-
That has two effects:
5+
У такого выделения есть два эффекта:
66

7-
1. It allows to place a part of the match into a separate array.
8-
2. If we put a quantifier after the parentheses, it applies to the parentheses as a whole, not the last character.
7+
1. Позволяет поместить часть совпадения в отдельный массив.
8+
2. Если установить квантификтор после скобок, то он будет применяться к всему содержимому скобки, а не к одному символу.
99

10-
## Example
10+
## Пример
1111

12-
In the example below the pattern `pattern:(go)+` finds one or more `match:'go'`:
12+
В примере ниже шаблон `pattern:(go)+` один или более `match:'go'`:
1313

1414
```js run
1515
alert( 'Gogogo now!'.match(/(go)+/i) ); // "Gogogo"
1616
```
1717

18-
Without parentheses, the pattern `pattern:/go+/` means `subject:g`, followed by `subject:o` repeated one or more times. For instance, `match:goooo` or `match:gooooooooo`.
18+
Без скобок, шаблон `pattern:/go+/` означает `subject:g` и, идущий после него, `subject:o`, который повторяется один или более раз. Например, `match:goooo` или `match:gooooooooo`.
1919

20-
Parentheses group the word `pattern:(go)` together.
20+
Скобки группирую символы в слово `pattern:(go)`.
2121

22-
Let's make something more complex -- a regexp to match an email.
22+
Сделаем что-то более сложное -- регулярное выражение, которое соответствует адресу электронной почты.
2323

24-
Examples of emails:
24+
Пример такой почты:
2525

2626
```
2727
my@mail.com
2828
john.smith@site.com.uk
2929
```
3030

31-
The pattern: `pattern:[-.\w]+@([\w-]+\.)+[\w-]{2,20}`.
31+
Шаблон: `pattern:[-.\w]+@([\w-]+\.)+[\w-]{2,20}`.
3232

33-
1. The first part `pattern:[-.\w]+` (before `@`) may include any alphanumeric word characters, a dot and a dash, to match `match:john.smith`.
34-
2. Then `pattern:@`, and the domain. It may be a subdomain like `host.site.com.uk`, so we match it as "a word followed by a dot `pattern:([\w-]+\.)` (repeated), and then the last part must be a word: `match:com` or `match:uk` (but not very long: 2-20 characters).
33+
1. Первая часть `pattern:[-.\w]+` (перед `@`) может включать любые числовые или буквенные символы, точку и тире, чтобы соответствовать `match:john.smith`.
34+
2. Затем идет `pattern:@` и домен. Это может быть поддомен (например, `host.site.com.uk`), поэтому мы сопоставляем его как слово, за которым следует точка `pattern:([\w-]+\.)` (повторяется). Затем в конце должно быть слово: `match:com` или `match:uk` (но не очень длинное: 2-20 символов).
3535

36-
That regexp is not perfect, but good enough to fix errors or occasional mistypes.
36+
Это выражение не идеально, но достаточно хорошее для исправления ошибок и опечаток.
3737

38-
For instance, we can find all emails in the string:
38+
Например, мы можем найти все электронные адреса в строке:
3939

4040
```js run
4141
let reg = /[-.\w]+@([\w-]+\.)+[\w-]{2,20}/g;
4242

4343
alert("my@mail.com @ his@site.com.uk".match(reg)); // my@mail.com, his@site.com.uk
4444
```
4545

46-
In this example parentheses were used to make a group for repeating `pattern:(...)+`. But there are other uses too, let's see them.
46+
В примере скобки используются для создания повторяющейся группы `pattern:(...)+`. Но есть и другие применения. Посмотрим на них.
4747

4848
## Contents of parentheses
4949

0 commit comments

Comments
 (0)