Skip to content

Commit 214ce99

Browse files
Update solution.md
1 parent fd901d2 commit 214ce99

File tree

1 file changed

+6
-7
lines changed
  • 9-regular-expressions/14-regexp-lookahead-lookbehind/1-find-non-negative-integers

1 file changed

+6
-7
lines changed

9-regular-expressions/14-regexp-lookahead-lookbehind/1-find-non-negative-integers/solution.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
Регулярний вираз для цілого числа `pattern:\d+`.
12

2-
The regexp for an integer number is `pattern:\d+`.
3+
Ми можемо виключити від'ємні числа попередньо написавши регулярний вираз для негативного перегляду назад: `pattern:(?<!-)\d+`.
34

4-
We can exclude negatives by prepending it with the negative lookbehind: `pattern:(?<!-)\d+`.
5-
6-
Although, if we try it now, we may notice one more "extra" result:
5+
Хоча, випробувавши його, ми побачимо одне "екстра" співпадіння:
76

87
```js run
98
let regexp = /(?<!-)\d+/g;
@@ -13,11 +12,11 @@ let str = "0 12 -5 123 -18";
1312
console.log( str.match(regexp) ); // 0, 12, 123, *!*8*/!*
1413
```
1514

16-
As you can see, it matches `match:8`, from `subject:-18`. To exclude it, we need to ensure that the regexp starts matching a number not from the middle of another (non-matching) number.
15+
Як ви бачите, шаблон знаходить `match:8`, у `subject:-18`. Щоб виключит і його, нам необхідно переконатись, що регулярний вираз починає пошук не з середини іншого не піходящого числа.
1716

18-
We can do it by specifying another negative lookbehind: `pattern:(?<!-)(?<!\d)\d+`. Now `pattern:(?<!\d)` ensures that a match does not start after another digit, just what we need.
17+
Ми можемо це реалізувати вказавши додатковий вираз для негативного перегляду назад: `pattern:(?<!-)(?<!\d)\d+`. Зараз `pattern:(?<!\d)` перевіряє, щоб пошук не починався одразу після іншого числа, як нам і було потрібно.
1918

20-
We can also join them into a single lookbehind here:
19+
Ми можемо об'єднати вирази в один таким чином:
2120

2221
```js run
2322
let regexp = /(?<![-\d])\d+/g;

0 commit comments

Comments
 (0)