Skip to content

Commit fb7cbac

Browse files
authored
Merge pull request #490 from joaquinelio/taka
9-14 lookaround tareas -atado otro pr -resolver #385 primero- x temas de glosario
2 parents 8f5eab0 + 8550670 commit fb7cbac

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
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 expresión regular para un número entero es `pattern:\d+`.
33

4-
We can exclude negatives by prepending it with the negative lookbehind: `pattern:(?<!-)\d+`.
4+
Podemos excluir los negativos anteponiendo un "lookbehind negativo": `pattern:(?<!-)\d+`.
55

6-
Although, if we try it now, we may notice one more "extra" result:
6+
Pero al probarlo, notamos un resultado de más:
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+
Como puedes ver, hay coincidencia de `match:8`, con `subject:-18`. Para excluirla necesitamos asegurarnos de que `regexp` no comience la búsqueda desde el medio de otro número (no coincidente).
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+
Podemos hacerlo especificando otra precedencia "lookbehind negativo": `pattern:(?<!-)(?<!\d)\d+`. Ahora `pattern:(?<!\d)` asegura que la coicidencia no comienza después de otro dígito, justo lo que necesitamos.
1919

20-
We can also join them into a single lookbehind here:
20+
También podemos unirlos en un único "lookbehind":
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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Find non-negative integers
1+
# Encontrar enteros no negativos
22

3-
There's a string of integer numbers.
3+
Tenemos un string de números enteros.
44

5-
Create a regexp that looks for only non-negative ones (zero is allowed).
5+
Crea una expresión regular que encuentre solamente los no negativos (el cero está permitido).
66

7-
An example of use:
7+
Un ejemplo de uso:
88
```js
9-
let regexp = /your regexp/g;
9+
let regexp = /tu regexp/g;
1010

1111
let str = "0 12 -5 123 -18";
1212

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
In order to insert after the `<body>` tag, we must first find it. We can use the regular expression pattern `pattern:<body.*?>` for that.
1+
Para insertar algo después de la etiqueta `<body>`, primero debemos encontrarla. Para ello podemos usar la expresión regular `pattern:<body.*?>`.
22

3-
In this task we don't need to modify the `<body>` tag. We only need to add the text after it.
3+
En esta tarea no debemos modificar la etiqueta `<body>`. Solamente agregar texto después de ella.
44

5-
Here's how we can do it:
5+
Veamos cómo podemos hacerlo:
66

77
```js run
88
let str = '...<body style="...">...';
@@ -11,9 +11,9 @@ str = str.replace(/<body.*?>/, '$&<h1>Hello</h1>');
1111
alert(str); // ...<body style="..."><h1>Hello</h1>...
1212
```
1313

14-
In the replacement string `$&` means the match itself, that is, the part of the source text that corresponds to `pattern:<body.*?>`. It gets replaced by itself plus `<h1>Hello</h1>`.
14+
En el string de reemplazo, `$&` significa la coincidencia misma, la parte del texto original que corresponde a `pattern:<body.*?>`. Es reemplazada por sí misma más `<h1>Hello</h1>`.
1515

16-
An alternative is to use lookbehind:
16+
Una alternativa es el uso de "lookbehind":
1717

1818
```js run
1919
let str = '...<body style="...">...';
@@ -22,15 +22,15 @@ str = str.replace(/(?<=<body.*?>)/, `<h1>Hello</h1>`);
2222
alert(str); // ...<body style="..."><h1>Hello</h1>...
2323
```
2424

25-
As you can see, there's only lookbehind part in this regexp.
25+
Como puedes ver, solo está presente la parte "lookbehind" en esta expresión regular.
2626

27-
It works like this:
28-
- At every position in the text.
29-
- Check if it's preceeded by `pattern:<body.*?>`.
30-
- If it's so then we have the match.
27+
Esto funciona así:
28+
- En cada posición en el texto.
29+
- Chequea si está precedida por `pattern:<body.*?>`.
30+
- Si es así, tenemos una coincidencia.
3131

32-
The tag `pattern:<body.*?>` won't be returned. The result of this regexp is literally an empty string, but it matches only at positions preceeded by `pattern:<body.*?>`.
32+
La etiqueta `pattern:<body.*?>` no será devuelta. El resultado de esta expresión regular es un string vacío, pero coincide solo en las posiciones precedidas por `pattern:<body.*?>`.
3333

34-
So it replaces the "empty line", preceeded by `pattern:<body.*?>`, with `<h1>Hello</h1>`. That's the insertion after `<body>`.
34+
Entonces reemplaza la "linea vacía", precedida por `pattern:<body.*?>`, con `<h1>Hello</h1>`. Esto es, la inserción después de `<body>`.
3535

36-
P.S. Regexp flags, such as `pattern:s` and `pattern:i` can also be useful: `pattern:/<body.*?>/si`. The `pattern:s` flag makes the dot `pattern:.` match a newline character, and `pattern:i` flag makes `pattern:<body>` also match `match:<BODY>` case-insensitively.
36+
P.S. Los indicadores de Regexp tales como `pattern:s` y `pattern:i` también nos pueden ser útiles: `pattern:/<body.*?>/si`. El indicador `pattern:s` hace que que el punto `pattern:.` coincida también con el carácter de salto de línea, y el indicador `pattern:i` hace que `pattern:<body>` también acepte coincidencias `match:<BODY>` en mayúsculas y minúsculas.

9-regular-expressions/14-regexp-lookahead-lookbehind/2-insert-after-head/task.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# Insert After Head
1+
# Insertar después de la cabecera
22

3-
We have a string with an HTML Document.
3+
Tenemos un string con un documento HTML.
44

5-
Write a regular expression that inserts `<h1>Hello</h1>` immediately after `<body>` tag. The tag may have attributes.
5+
Escribe una expresión regular que inserte `<h1>Hello</h1>` inmediatamente después de la etiqueta `<body>`. La etiqueta puede tener atributos.
66

7-
For instance:
7+
Por ejemplo:
88

99
```js
10-
let regexp = /your regular expression/;
10+
let regexp = /tu expresión regular/;
1111

1212
let str = `
1313
<html>
@@ -20,7 +20,7 @@ let str = `
2020
str = str.replace(regexp, `<h1>Hello</h1>`);
2121
```
2222

23-
After that the value of `str` should be:
23+
Después de esto el valor de `str` debe ser:
2424
```html
2525
<html>
2626
<body style="height: 200px"><h1>Hello</h1>

0 commit comments

Comments
 (0)