Skip to content

Commit 641fe99

Browse files
committed
Update 9-regular-expressions\14-regexp-lookahead-lookbehind
1 parent 34dd784 commit 641fe99

File tree

2 files changed

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

2 files changed

+9
-11
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

2-
The regexp for an integer number is `pattern:\d+`.
2+
La regexp per un numero intero è `pattern:\d+`.
33

4-
We can exclude negatives by prepending it with the negative lookbehind: `pattern:(?<!-)\d+`.
4+
Possiamo escludere i numeri negativi anteponendo il segno meno con il lookbehind: `pattern:(?<!-)\d+`.
55

6-
Although, if we try it now, we may notice one more "extra" result:
6+
Anche se, nel caso in cui lo provassimo ora, potremmo notare un altro risultato inatteso:
77

88
```js run
99
let regexp = /(?<!-)\d+/g;
@@ -13,11 +13,11 @@ let str = "0 12 -5 123 -18";
1313
console.log( str.match(regexp) ); // 0, 12, 123, *!*8*/!*
1414
```
1515

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.
16+
Come potete osservare trova `match:8` da `subject:-18`. Per escluderlo, dobbiamo assicurarci che la regexp non cominci a cercare una corrispondenza di un numero dalla metà di un altro numero non corrispondente.
1717

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.
18+
Possiamo farlo specificando un altro lookbehind negativo: `pattern:(?<!-)(?<!\d)\d+`. Ora `pattern:(?<!\d)` assicura che la corrispondenza non cominci dopo un altro numero, proprio quello che volevamo.
1919

20-
We can also join them into a single lookbehind here:
20+
Potremmo anche unire il tutto in un singolo lookbehind in questo modo:
2121

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

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
# Find non-negative integers
1+
# Trovate gli interi non negativi
22

3-
There's a string of integer numbers.
3+
Data una stringa di numeri interi, create una regexp che cerchi solo quelli non negativi (lo zero è consentito).
44

5-
Create a regexp that looks for only non-negative ones (zero is allowed).
6-
7-
An example of use:
5+
Un esempio d'uso:
86
```js
97
let regexp = /your regexp/g;
108

0 commit comments

Comments
 (0)