From fe370320058dfb9e39c8bbe20de065f713bbb5a3 Mon Sep 17 00:00:00 2001 From: AbiF73 <71402430+AbiF73@users.noreply.github.com> Date: Thu, 15 Oct 2020 17:41:04 -0300 Subject: [PATCH 01/10] Update article.md --- .../16-regexp-sticky/article.md | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/9-regular-expressions/16-regexp-sticky/article.md b/9-regular-expressions/16-regexp-sticky/article.md index f3650c916..65e36b3f3 100644 --- a/9-regular-expressions/16-regexp-sticky/article.md +++ b/9-regular-expressions/16-regexp-sticky/article.md @@ -1,56 +1,56 @@ -# Sticky flag "y", searching at position +# Indicador adhesivo “y”, buscando en una posición. -The flag `pattern:y` allows to perform the search at the given position in the source string. +EL indicador `pattern:y` permite realizar la búsqueda en una posición dada en el string de origen. -To grasp the use case of `pattern:y` flag, and see how great it is, let's explore a practical use case. +Para entender el caso de uso del indicador `pattern:y`, y ver que tan bueno es, exploremos un caso práctico de uso. -One of common tasks for regexps is "lexical analysis": we get a text, e.g. in a programming language, and analyze it for structural elements. +Una tarea común para regexps es "Analisis lexico": tenemos un texto, por ej. en un lenguaje de programación, y analiza sus elementos estructurales. -For instance, HTML has tags and attributes, JavaScript code has functions, variables, and so on. +Por ejemplo, HTML tiene etiquetas y atributos, el código JavaScript tiene funciones, variables, etc. -Writing lexical analyzers is a special area, with its own tools and algorithms, so we don't go deep in there, but there's a common task: to read something at the given position. +Escribir analizadores léxicos es un área especial, con sus propias herramientas y algoritmos, así que no profundizaremos en ello, pero existe una tarea común: leer algo en una posición dada. -E.g. we have a code string `subject:let varName = "value"`, and we need to read the variable name from it, that starts at position `4`. +Por ej. tenemos una cadena de código `subject:let varName = "value"`, y necesitamos leer el nombre de su variable, que comienza en la posición `4`. -We'll look for variable name using regexp `pattern:\w+`. Actually, JavaScript variable names need a bit more complex regexp for accurate matching, but here it doesn't matter. +Buscaremos el nombre de la variable usando regexp `pattern:\w+`. En realidad, el nombre de la variable de JavaScript necesita un regexp un poco más complejo para un emparejamiento más preciso, pero aquí eso no importa. -A call to `str.match(/\w+/)` will find only the first word in the line. Or all words with the flag `pattern:g`. But we need only one word at position `4`. +Una llamada a `str.match(/\w+/)` solo encontrará la primera palabra de la línea, o todas las palabras con el indicador `pattern:g`. Pero solo necesitamos una palabra en la posición `4`. -To search from the given position, we can use method `regexp.exec(str)`. +Para buscar desde la posición dada, usamos el método `regexp.exec(str)`. -If the `regexp` doesn't have flags `pattern:g` or `pattern:y`, then this method looks for the first match in the string `str`, exactly like `str.match(regexp)`. Such simple no-flags case doesn't interest us here. +Sí `regexp` no tiene indicadores `pattern:g` o `pattern:y`, entonces este método busca la primer coincidencia en el string `str`, exactamente como `str.match(regexp)`. Un caso tan simple sin indicadores no nos interesa aquí. -If there's flag `pattern:g`, then it performs the search in the string `str`, starting from position stored in its `regexp.lastIndex` property. And, if it finds a match, then sets `regexp.lastIndex` to the index immediately after the match. +Sí hay indicador `pattern:g`, realiza la búsqueda en el string `str`, empezando desde la posición almacenada en su propiedad `regexp.lastIndex`. Y, si encuentra una coincidencia, entonces establece `regexp.lastIndex` en el index inmediatamente después del emparejamiento. -When a regexp is created, its `lastIndex` is `0`. +Cuando un regex es creado, su `lastIndex` es `0`. -So, successive calls to `regexp.exec(str)` return matches one after another. +Entonces, llamadas sucesivas a `regexp.exec(str)` devuelve coincidencias una después de la otra. -An example (with flag `pattern:g`): +Un ejemplo (con el indicador `pattern:g`): ```js run let str = 'let varName'; let regexp = /\w+/g; -alert(regexp.lastIndex); // 0 (initially lastIndex=0) +alert(regexp.lastIndex); // 0 (inicialmente lastIndex=0) let word1 = regexp.exec(str); -alert(word1[0]); // let (1st word) -alert(regexp.lastIndex); // 3 (position after the match) +alert(word1[0]); // let (1er palabra) +alert(regexp.lastIndex); // 3 (Posición posterior al emparejamiento) let word2 = regexp.exec(str); -alert(word2[0]); // varName (2nd word) -alert(regexp.lastIndex); // 11 (position after the match) +alert(word2[0]); // varName (2da palabra) +alert(regexp.lastIndex); // 11 (Posición posterior al emparejamiento) let word3 = regexp.exec(str); -alert(word3); // null (no more matches) -alert(regexp.lastIndex); // 0 (resets at search end) +alert(word3); // null (no más emparejamientos) +alert(regexp.lastIndex); // 0 (reinicia en el final de la búsqueda) ``` -Every match is returned as an array with groups and additional properties. +Cada coincidencia es devuelta como un array con grupos y propiedades adicionales. -We can get all matches in the loop: +Podemos conseguir todas las coincidencias en el loop: ```js run let str = 'let varName'; @@ -65,16 +65,16 @@ while (result = regexp.exec(str)) { } ``` -Such use of `regexp.exec` is an alternative to method `str.matchAll`. +Tal uso de `regexp.exec` es una alternativa para el método `str.match bAll`. -Unlike other methods, we can set our own `lastIndex`, to start the search from the given position. +A diferencia de otros métodos, podemos establecer nuestro propio `lastIndex`, para comenzar la búsqueda desde la posición dada. -For instance, let's find a word, starting from position `4`: +Por ejemplo, encontremos una palabra, comenzando desde la posición `4`: ```js run let str = 'let varName = "value"'; -let regexp = /\w+/g; // without flag "g", property lastIndex is ignored +let regexp = /\w+/g; // Sin el indicador “g”, la propiedad lastindex es ignorada. *!* regexp.lastIndex = 4; @@ -84,9 +84,9 @@ let word = regexp.exec(str); alert(word); // varName ``` -We performed a search of `pattern:\w+`, starting from position `regexp.lastIndex = 4`. +Realizamos una búsqueda de `pattern:\w+`, comenzando desde la posición `regexp.lastIndex = 4`. -Please note: the search starts at position `lastIndex` and then goes further. If there's no word at position `lastIndex`, but it's somewhere after it, then it will be found: +Por favor nota que la búsqueda comienza en la posición `lastIndex` y luego profundiza. Sí no hay ninguna palabra en la posición `lastIndex`, pero está en algún lugar posterior, entonces será encontrada: ```js run let str = 'let varName = "value"'; @@ -102,11 +102,11 @@ alert(word[0]); // varName alert(word.index); // 4 ``` -...So, with flag `pattern:g` property `lastIndex` sets the starting position for the search. +...Así que, con la propiedad `lastIndex` del indicador `pattern:g` se establece la posición inicial de la búsqueda. -**Flag `pattern:y` makes `regexp.exec` to look exactly at position `lastIndex`, not before, not after it.** +**El indicador `pattern:y` hace que `regexp.exec` busque exactamente en la posición `lastIndex`, ni antes ni después.** -Here's the same search with flag `pattern:y`: +Aquí está la misma búsqueda con el indicador `pattern:y`: ```js run let str = 'let varName = "value"'; @@ -114,14 +114,14 @@ let str = 'let varName = "value"'; let regexp = /\w+/y; regexp.lastIndex = 3; -alert( regexp.exec(str) ); // null (there's a space at position 3, not a word) +alert( regexp.exec(str) ); // null (Hay un espacio en la posición 3, no una palabra) regexp.lastIndex = 4; -alert( regexp.exec(str) ); // varName (word at position 4) +alert( regexp.exec(str) ); // varName (Una palabra en la posición 4) ``` -As we can see, regexp `pattern:/\w+/y` doesn't match at position `3` (unlike the flag `pattern:g`), but matches at position `4`. +Como podemos ver, el `pattern:/\w+/y` de regexp no coincide en la posición `3` (a diferencia del indicador `pattern:g`), pero coincide en la posición `4`. -Imagine, we have a long text, and there are no matches in it, at all. Then searching with flag `pattern:g` will go till the end of the text, and this will take significantly more time than the search with flag `pattern:y`. +Imagina que tenemos un texto largo, y no hay coincidencias en él. Entonces la búsqueda con el indicador `pattern:g` irá hasta el final del texto, y esto tomará significativamente más tiempo que la búsqueda con el indicador `pattern:y`. -In such tasks like lexical analysis, there are usually many searches at an exact position. Using flag `pattern:y` is the key for a good performance. +En tales tareas como el análisis léxico, normalmente hay muchas búsquedas en una posición exacta. Usar el indicador `pattern:y` es la clave para un buen desempeño. From 47690827b6d130cd18c4958d43945a3b9bfc38ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=90=AF=E1=91=AD=E1=92=AAE=E1=91=8ETI=E1=91=8E=E1=97=A9?= =?UTF-8?q?=E1=99=AD=20=E1=90=AF=E1=91=AD?= <34555644+vplentinax@users.noreply.github.com> Date: Thu, 17 Dec 2020 13:14:37 -0400 Subject: [PATCH 02/10] Update 9-regular-expressions/16-regexp-sticky/article.md Co-authored-by: joaquinelio --- 9-regular-expressions/16-regexp-sticky/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/9-regular-expressions/16-regexp-sticky/article.md b/9-regular-expressions/16-regexp-sticky/article.md index 65e36b3f3..6d29ecaef 100644 --- a/9-regular-expressions/16-regexp-sticky/article.md +++ b/9-regular-expressions/16-regexp-sticky/article.md @@ -3,7 +3,7 @@ EL indicador `pattern:y` permite realizar la búsqueda en una posición dada en el string de origen. -Para entender el caso de uso del indicador `pattern:y`, y ver que tan bueno es, exploremos un caso práctico de uso. +Para entender el caso de uso del indicador `pattern:y`, y ver lo notable que es, exploremos un ejemplo práctico. Una tarea común para regexps es "Analisis lexico": tenemos un texto, por ej. en un lenguaje de programación, y analiza sus elementos estructurales. From b57677130299e3c3a696236a895e3feefcb67b88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=90=AF=E1=91=AD=E1=92=AAE=E1=91=8ETI=E1=91=8E=E1=97=A9?= =?UTF-8?q?=E1=99=AD=20=E1=90=AF=E1=91=AD?= <34555644+vplentinax@users.noreply.github.com> Date: Thu, 17 Dec 2020 13:14:46 -0400 Subject: [PATCH 03/10] Update 9-regular-expressions/16-regexp-sticky/article.md Co-authored-by: joaquinelio --- 9-regular-expressions/16-regexp-sticky/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/9-regular-expressions/16-regexp-sticky/article.md b/9-regular-expressions/16-regexp-sticky/article.md index 6d29ecaef..5c8175a19 100644 --- a/9-regular-expressions/16-regexp-sticky/article.md +++ b/9-regular-expressions/16-regexp-sticky/article.md @@ -5,7 +5,7 @@ EL indicador `pattern:y` permite realizar la búsqueda en una posición dada en Para entender el caso de uso del indicador `pattern:y`, y ver lo notable que es, exploremos un ejemplo práctico. -Una tarea común para regexps es "Analisis lexico": tenemos un texto, por ej. en un lenguaje de programación, y analiza sus elementos estructurales. +Una tarea común para regexps es el "Análisis léxico": tenemos un texto, por ej. en un lenguaje de programación, y analiza sus elementos estructurales. Por ejemplo, HTML tiene etiquetas y atributos, el código JavaScript tiene funciones, variables, etc. From 12bf85250353a13c1b40e9cea8fb18f580dfe312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=90=AF=E1=91=AD=E1=92=AAE=E1=91=8ETI=E1=91=8E=E1=97=A9?= =?UTF-8?q?=E1=99=AD=20=E1=90=AF=E1=91=AD?= <34555644+vplentinax@users.noreply.github.com> Date: Thu, 17 Dec 2020 13:15:01 -0400 Subject: [PATCH 04/10] Update 9-regular-expressions/16-regexp-sticky/article.md Co-authored-by: joaquinelio --- 9-regular-expressions/16-regexp-sticky/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/9-regular-expressions/16-regexp-sticky/article.md b/9-regular-expressions/16-regexp-sticky/article.md index 5c8175a19..88555c905 100644 --- a/9-regular-expressions/16-regexp-sticky/article.md +++ b/9-regular-expressions/16-regexp-sticky/article.md @@ -9,7 +9,7 @@ Una tarea común para regexps es el "Análisis léxico": tenemos un texto, por e Por ejemplo, HTML tiene etiquetas y atributos, el código JavaScript tiene funciones, variables, etc. -Escribir analizadores léxicos es un área especial, con sus propias herramientas y algoritmos, así que no profundizaremos en ello, pero existe una tarea común: leer algo en una posición dada. +Escribir analizadores léxicos es un área especial, con sus propias herramientas y algoritmos, así que no profundizaremos en ello; pero existe una tarea común: leer algo en una posición dada. Por ej. tenemos una cadena de código `subject:let varName = "value"`, y necesitamos leer el nombre de su variable, que comienza en la posición `4`. From 75a942e3b505b5a2b00fdba71ec3590a6c70a21b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=90=AF=E1=91=AD=E1=92=AAE=E1=91=8ETI=E1=91=8E=E1=97=A9?= =?UTF-8?q?=E1=99=AD=20=E1=90=AF=E1=91=AD?= <34555644+vplentinax@users.noreply.github.com> Date: Thu, 17 Dec 2020 13:15:10 -0400 Subject: [PATCH 05/10] Update 9-regular-expressions/16-regexp-sticky/article.md Co-authored-by: joaquinelio --- 9-regular-expressions/16-regexp-sticky/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/9-regular-expressions/16-regexp-sticky/article.md b/9-regular-expressions/16-regexp-sticky/article.md index 88555c905..ff1051d0f 100644 --- a/9-regular-expressions/16-regexp-sticky/article.md +++ b/9-regular-expressions/16-regexp-sticky/article.md @@ -19,7 +19,7 @@ Una llamada a `str.match(/\w+/)` solo encontrará la primera palabra de la líne Para buscar desde la posición dada, usamos el método `regexp.exec(str)`. -Sí `regexp` no tiene indicadores `pattern:g` o `pattern:y`, entonces este método busca la primer coincidencia en el string `str`, exactamente como `str.match(regexp)`. Un caso tan simple sin indicadores no nos interesa aquí. +Sí `regexp` no tiene indicadores `pattern:g` o `pattern:y`, entonces este método busca la primera coincidencia en el string `str`, exactamente como `str.match(regexp)`. Un caso tan simple sin indicadores no nos interesa aquí. Sí hay indicador `pattern:g`, realiza la búsqueda en el string `str`, empezando desde la posición almacenada en su propiedad `regexp.lastIndex`. Y, si encuentra una coincidencia, entonces establece `regexp.lastIndex` en el index inmediatamente después del emparejamiento. From 06bd4686bb252ad2a2029cd11a958e234072a490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=90=AF=E1=91=AD=E1=92=AAE=E1=91=8ETI=E1=91=8E=E1=97=A9?= =?UTF-8?q?=E1=99=AD=20=E1=90=AF=E1=91=AD?= <34555644+vplentinax@users.noreply.github.com> Date: Thu, 17 Dec 2020 13:15:23 -0400 Subject: [PATCH 06/10] Update 9-regular-expressions/16-regexp-sticky/article.md Co-authored-by: joaquinelio --- 9-regular-expressions/16-regexp-sticky/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/9-regular-expressions/16-regexp-sticky/article.md b/9-regular-expressions/16-regexp-sticky/article.md index ff1051d0f..9475b53bb 100644 --- a/9-regular-expressions/16-regexp-sticky/article.md +++ b/9-regular-expressions/16-regexp-sticky/article.md @@ -21,7 +21,7 @@ Para buscar desde la posición dada, usamos el método `regexp.exec(str)`. Sí `regexp` no tiene indicadores `pattern:g` o `pattern:y`, entonces este método busca la primera coincidencia en el string `str`, exactamente como `str.match(regexp)`. Un caso tan simple sin indicadores no nos interesa aquí. -Sí hay indicador `pattern:g`, realiza la búsqueda en el string `str`, empezando desde la posición almacenada en su propiedad `regexp.lastIndex`. Y, si encuentra una coincidencia, entonces establece `regexp.lastIndex` en el index inmediatamente después del emparejamiento. +Si existe el indicador `pattern:g`, realiza la búsqueda en el string `str` empezando desde la posición almacenada en su propiedad `regexp.lastIndex`. Y si encuentra una coincidencia, establece `regexp.lastIndex` en el index inmediatamente después del emparejamiento. Cuando un regex es creado, su `lastIndex` es `0`. From 8f9d5dd4f37c2ad97877c9ff730c8723eec7d3b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=90=AF=E1=91=AD=E1=92=AAE=E1=91=8ETI=E1=91=8E=E1=97=A9?= =?UTF-8?q?=E1=99=AD=20=E1=90=AF=E1=91=AD?= <34555644+vplentinax@users.noreply.github.com> Date: Thu, 17 Dec 2020 13:15:56 -0400 Subject: [PATCH 07/10] Update 9-regular-expressions/16-regexp-sticky/article.md Co-authored-by: joaquinelio --- 9-regular-expressions/16-regexp-sticky/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/9-regular-expressions/16-regexp-sticky/article.md b/9-regular-expressions/16-regexp-sticky/article.md index 9475b53bb..c5011c951 100644 --- a/9-regular-expressions/16-regexp-sticky/article.md +++ b/9-regular-expressions/16-regexp-sticky/article.md @@ -36,7 +36,7 @@ let regexp = /\w+/g; alert(regexp.lastIndex); // 0 (inicialmente lastIndex=0) let word1 = regexp.exec(str); -alert(word1[0]); // let (1er palabra) +alert(word1[0]); // let (primera palabra) alert(regexp.lastIndex); // 3 (Posición posterior al emparejamiento) let word2 = regexp.exec(str); From 38d35061c2993e5a16ab0dbef85da7c2a037e605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=90=AF=E1=91=AD=E1=92=AAE=E1=91=8ETI=E1=91=8E=E1=97=A9?= =?UTF-8?q?=E1=99=AD=20=E1=90=AF=E1=91=AD?= <34555644+vplentinax@users.noreply.github.com> Date: Thu, 17 Dec 2020 13:16:18 -0400 Subject: [PATCH 08/10] Update 9-regular-expressions/16-regexp-sticky/article.md Co-authored-by: joaquinelio --- 9-regular-expressions/16-regexp-sticky/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/9-regular-expressions/16-regexp-sticky/article.md b/9-regular-expressions/16-regexp-sticky/article.md index c5011c951..a41e3ff9b 100644 --- a/9-regular-expressions/16-regexp-sticky/article.md +++ b/9-regular-expressions/16-regexp-sticky/article.md @@ -65,7 +65,7 @@ while (result = regexp.exec(str)) { } ``` -Tal uso de `regexp.exec` es una alternativa para el método `str.match bAll`. +Tal uso de `regexp.exec` es una alternativa al método `str.match bAll`. A diferencia de otros métodos, podemos establecer nuestro propio `lastIndex`, para comenzar la búsqueda desde la posición dada. From 041b2e4ddf2a2e0f003ecf268cab982f4c2ccde7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=90=AF=E1=91=AD=E1=92=AAE=E1=91=8ETI=E1=91=8E=E1=97=A9?= =?UTF-8?q?=E1=99=AD=20=E1=90=AF=E1=91=AD?= <34555644+vplentinax@users.noreply.github.com> Date: Thu, 17 Dec 2020 13:16:33 -0400 Subject: [PATCH 09/10] Update 9-regular-expressions/16-regexp-sticky/article.md Co-authored-by: joaquinelio --- 9-regular-expressions/16-regexp-sticky/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/9-regular-expressions/16-regexp-sticky/article.md b/9-regular-expressions/16-regexp-sticky/article.md index a41e3ff9b..aaafe2c13 100644 --- a/9-regular-expressions/16-regexp-sticky/article.md +++ b/9-regular-expressions/16-regexp-sticky/article.md @@ -86,7 +86,7 @@ alert(word); // varName Realizamos una búsqueda de `pattern:\w+`, comenzando desde la posición `regexp.lastIndex = 4`. -Por favor nota que la búsqueda comienza en la posición `lastIndex` y luego profundiza. Sí no hay ninguna palabra en la posición `lastIndex`, pero está en algún lugar posterior, entonces será encontrada: +Nota que la búsqueda comienza en la posición `lastIndex` y luego sigue adelante. Si no hay ninguna palabra en la posición `lastIndex` pero la hay en algún lugar posterior, entonces será encontrada: ```js run let str = 'let varName = "value"'; From 9e5770518b33ea9e419ef89d8a785ef438cbfb90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=90=AF=E1=91=AD=E1=92=AAE=E1=91=8ETI=E1=91=8E=E1=97=A9?= =?UTF-8?q?=E1=99=AD=20=E1=90=AF=E1=91=AD?= <34555644+vplentinax@users.noreply.github.com> Date: Thu, 17 Dec 2020 13:16:41 -0400 Subject: [PATCH 10/10] Update 9-regular-expressions/16-regexp-sticky/article.md Co-authored-by: joaquinelio --- 9-regular-expressions/16-regexp-sticky/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/9-regular-expressions/16-regexp-sticky/article.md b/9-regular-expressions/16-regexp-sticky/article.md index aaafe2c13..476410cd3 100644 --- a/9-regular-expressions/16-regexp-sticky/article.md +++ b/9-regular-expressions/16-regexp-sticky/article.md @@ -124,4 +124,4 @@ Como podemos ver, el `pattern:/\w+/y` de regexp no coincide en la posición `3` Imagina que tenemos un texto largo, y no hay coincidencias en él. Entonces la búsqueda con el indicador `pattern:g` irá hasta el final del texto, y esto tomará significativamente más tiempo que la búsqueda con el indicador `pattern:y`. -En tales tareas como el análisis léxico, normalmente hay muchas búsquedas en una posición exacta. Usar el indicador `pattern:y` es la clave para un buen desempeño. +En tareas tales como el análisis léxico, normalmente hay muchas búsquedas en una posición exacta. Usar el indicador `pattern:y` es la clave para un buen desempeño. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy