Skip to content

Commit 5d10e83

Browse files
authored
Update solution.md
1 parent c42b048 commit 5d10e83

File tree

1 file changed

+3
-18
lines changed
  • 9-regular-expressions/14-regexp-lookahead-lookbehind/2-insert-after-head

1 file changed

+3
-18
lines changed
Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
Para insertar algo después de la etiqueta `<body>`, primero debemos encontrarla. Para ello podemos usar la expresión regular `pattern:<body.*?>`.
22

3-
<<<<<<< HEAD
4-
En esta tarea no debemos modificar la etiqueta `<body>`. Solamente agregar texto después de ella.
5-
=======
6-
In this task, we don't need to modify the `<body>` tag. We only need to add the text after it.
7-
>>>>>>> 7bb6066eb6ea3a030b875cdc75433c458f80997e
3+
En esta tarea no necsitamos modificar la etiqueta `<body>`. Solamente agregar texto después de ella.
84

95
Veamos cómo podemos hacerlo:
106

@@ -28,24 +24,13 @@ alert(str); // ...<body style="..."><h1>Hello</h1>...
2824

2925
Como puedes ver, solo está presente la parte "lookbehind" en esta expresión regular.
3026

31-
<<<<<<< HEAD
3227
Esto funciona así:
33-
- En cada posición en el texto.
34-
- Chequea si está precedida por `pattern:<body.*?>`.
28+
- En cada posición en el texto:
29+
- Verifica si está precedida por `pattern:<body.*?>`.
3530
- Si es así, tenemos una coincidencia.
3631

3732
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.*?>`.
3833

3934
Entonces reemplaza la "linea vacía", precedida por `pattern:<body.*?>`, con `<h1>Hello</h1>`. Esto es, la inserción después de `<body>`.
40-
=======
41-
It works like this:
42-
- At every position in the text.
43-
- Check if it's preceded by `pattern:<body.*?>`.
44-
- If it's so, then we have the match.
45-
46-
The tag `pattern:<body.*?>` won't be returned. The result of this regexp is literally an empty string, but it matches only at positions preceded by `pattern:<body.*?>`.
47-
48-
So it replaces the "empty line", preceded by `pattern:<body.*?>`, with `<h1>Hello</h1>`. That's the insertion after `<body>`.
49-
>>>>>>> 7bb6066eb6ea3a030b875cdc75433c458f80997e
5035

5136
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.

0 commit comments

Comments
 (0)