Skip to content

Commit 6583bb4

Browse files
authored
Merge pull request #355 from cortizg/es.javascript.info.9-10-glq
Greedy and lazy quantifiers
2 parents 371186a + fb7a0c4 commit 6583bb4

File tree

7 files changed

+140
-140
lines changed

7 files changed

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

2-
The result is: `match:123 4`.
2+
El resultado es: `match:123 4`.
33

4-
First the lazy `pattern:\d+?` tries to take as little digits as it can, but it has to reach the space, so it takes `match:123`.
4+
Primero el perezoso `pattern:\d+?` trata de tomar la menor cantidad de dígitos posible, pero tiene que llegar al espacio, por lo que toma `match:123`.
55

6-
Then the second `\d+?` takes only one digit, because that's enough.
6+
Después el segundo `\d+?` toma solo un dígito, porque es sufuciente.

9-regular-expressions/10-regexp-greedy-and-lazy/1-lazy-greedy/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# A match for /d+? d+?/
1+
# Una coincidencia para /d+? d+?/
22

3-
What's the match here?
3+
¿Cual es la coincidencia aquí?
44

55
```js
66
"123 456".match(/\d+? \d+?/g) ); // ?
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
We need to find the beginning of the comment `match:<!--`, then everything till the end of `match:-->`.
1+
Necesitamos encontrar el inicio del comentario `match:<!--`, después todo hasta el fin de `match:-->`.
22

3-
An acceptable variant is `pattern:<!--.*?-->` -- the lazy quantifier makes the dot stop right before `match:-->`. We also need to add flag `pattern:s` for the dot to include newlines.
3+
Una variante aceptable es `pattern:<!--.*?-->` -- el cuantificador perezoso detiene el punto justo antes de `match:-->`. También necesitamos agregar la bandera `pattern:s` al punto para incluir líneas nuevas.
44

5-
Otherwise multiline comments won't be found:
5+
De lo contrario, no se encontrarán comentarios multilínea:
66

77
```js run
88
let regexp = /<!--.*?-->/gs;
99

10-
let str = `... <!-- My -- comment
11-
test --> .. <!----> ..
10+
let str = `... <!-- Mi -- comentario
11+
prueba --> .. <!----> ..
1212
`;
1313

14-
alert( str.match(regexp) ); // '<!-- My -- comment \n test -->', '<!---->'
14+
alert( str.match(regexp) ); // '<!-- Mi -- comentario \n prueba -->', '<!---->'
1515
```
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# Find HTML comments
1+
# Encuentra el comentario HTML
22

3-
Find all HTML comments in the text:
3+
Encuentra todos los comentarios HTML en el texto:
44

55
```js
66
let regexp = /your regexp/g;
77

8-
let str = `... <!-- My -- comment
9-
test --> .. <!----> ..
8+
let str = `... <!-- Mi -- comentario
9+
prueba --> .. <!----> ..
1010
`;
1111

12-
alert( str.match(regexp) ); // '<!-- My -- comment \n test -->', '<!---->'
12+
alert( str.match(regexp) ); // '<!-- Mi -- comentario \n prueba -->', '<!---->'
1313
```
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

2-
The solution is `pattern:<[^<>]+>`.
2+
La solución es `pattern:<[^<>]+>`.
33

44
```js run
55
let regexp = /<[^<>]+>/g;
66

7-
let str = '<> <a href="/"> <input type="radio" checked> <b>';
7+
let str = '<> <a href="/"> <input type="radio" checked > <b>';
88

9-
alert( str.match(regexp) ); // '<a href="/">', '<input type="radio" checked>', '<b>'
9+
alert( str.match(regexp) ); // '<a href="/">', '<input type="radio" checked >', '<b>'
1010
```
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
# Find HTML tags
1+
# Encontrar las etiquetas HTML
22

3-
Create a regular expression to find all (opening and closing) HTML tags with their attributes.
3+
Crear una expresión regular para encontrar todas las etiquetas HTML (de apertura y cierre) con sus atributos.
44

5-
An example of use:
5+
Un ejemplo de uso:
66

77
```js run
8-
let regexp = /your regexp/g;
8+
let regexp = /tu regexp/g;
99

10-
let str = '<> <a href="/"> <input type="radio" checked> <b>';
10+
let str = '<> <a href="/"> <input type="radio" checked > <b>';
1111

12-
alert( str.match(regexp) ); // '<a href="/">', '<input type="radio" checked>', '<b>'
12+
alert( str.match(regexp) ); // '<a href="/">', '<input type="radio" checked >', '<b>'
1313
```
1414

15-
Here we assume that tag attributes may not contain `<` and `>` (inside squotes too), that simplifies things a bit.
15+
Asumimos que los atributos de etiqueta no deben contener `<` ni `>` (dentro de comillas dobles también), esto simplifica un poco las cosas.

0 commit comments

Comments
 (0)