diff --git a/9-regular-expressions/13-regexp-alternation/01-find-programming-language/solution.md b/9-regular-expressions/13-regexp-alternation/01-find-programming-language/solution.md index e33f9cf2f..53d2df443 100644 --- a/9-regular-expressions/13-regexp-alternation/01-find-programming-language/solution.md +++ b/9-regular-expressions/13-regexp-alternation/01-find-programming-language/solution.md @@ -1,7 +1,7 @@ -The first idea can be to list the languages with `|` in-between. +La primera idea puede ser listar los idiomas con `|` en el medio. -But that doesn't work right: +Pero eso no funciona bien: ```js run let regexp = /Java|JavaScript|PHP|C|C\+\+/g; @@ -11,18 +11,18 @@ let str = "Java, JavaScript, PHP, C, C++"; alert( str.match(regexp) ); // Java,Java,PHP,C,C ``` -The regular expression engine looks for alternations one-by-one. That is: first it checks if we have `match:Java`, otherwise -- looks for `match:JavaScript` and so on. +El motor de expresiones regulares busca las alternancias una por una. Es decir: primero verifica si tenemos `match: Java`, de lo contrario - busca `match: JavaScript` y así sucesivamente. -As a result, `match:JavaScript` can never be found, just because `match:Java` is checked first. +Como resultado, nunca se puede encontrar `match: JavaScript`, simplemente porque encuentra primero `match: Java`. -The same with `match:C` and `match:C++`. +Lo mismo con `match: C` y `match: C++ `. -There are two solutions for that problem: +Hay dos soluciones para ese problema: -1. Change the order to check the longer match first: `pattern:JavaScript|Java|C\+\+|C|PHP`. -2. Merge variants with the same start: `pattern:Java(Script)?|C(\+\+)?|PHP`. +1. Cambiar el orden para comprobar primero la coincidencia más larga: `pattern:JavaScript|Java|C\+\+|C|PHP`. +2. Fusionar variantes con el mismo inicio: `pattern:Java(Script)?|C(\+\+)?|PHP`. -In action: +En acción: ```js run let regexp = /Java(Script)?|C(\+\+)?|PHP/g; diff --git a/9-regular-expressions/13-regexp-alternation/01-find-programming-language/task.md b/9-regular-expressions/13-regexp-alternation/01-find-programming-language/task.md index e0f7af95c..c968de6bd 100644 --- a/9-regular-expressions/13-regexp-alternation/01-find-programming-language/task.md +++ b/9-regular-expressions/13-regexp-alternation/01-find-programming-language/task.md @@ -1,8 +1,8 @@ -# Find programming languages +# Encuentra lenguajes de programación -There are many programming languages, for instance Java, JavaScript, PHP, C, C++. +Hay muchos lenguajes de programación, por ejemplo, Java, JavaScript, PHP, C, C ++. -Create a regexp that finds them in the string `subject:Java JavaScript PHP C++ C`: +Crea una expresión regular que los encuentre en la cadena `subject:Java JavaScript PHP C++ C`: ```js let regexp = /your regexp/g; diff --git a/9-regular-expressions/13-regexp-alternation/02-find-matching-bbtags/solution.md b/9-regular-expressions/13-regexp-alternation/02-find-matching-bbtags/solution.md index 9b3fa1877..184c3fd6c 100644 --- a/9-regular-expressions/13-regexp-alternation/02-find-matching-bbtags/solution.md +++ b/9-regular-expressions/13-regexp-alternation/02-find-matching-bbtags/solution.md @@ -1,11 +1,11 @@ -Opening tag is `pattern:\[(b|url|quote)\]`. +La etiqueta de apertura es `pattern:\[(b|url|quote)\]`. -Then to find everything till the closing tag -- let's use the pattern `pattern:.*?` with flag `pattern:s` to match any character including the newline and then add a backreference to the closing tag. +Luego, para encontrar todo hasta la etiqueta de cierre, usemos el patrón`pattern:.*?` con la bandera `pattern:s` para que coincida con cualquier carácter, incluida la nueva línea, y luego agreguemos una referencia inversa a la etiqueta de cierre. -The full pattern: `pattern:\[(b|url|quote)\].*?\[/\1\]`. +El patrón completo: `pattern:\[(b|url|quote)\].*?\[/\1\]`. -In action: +En acción: ```js run let regexp = /\[(b|url|quote)\].*?\[\/\1\]/gs; @@ -20,4 +20,4 @@ let str = ` alert( str.match(regexp) ); // [b]hello![/b],[quote][url]http://google.com[/url][/quote] ``` -Please note that besides escaping `pattern:[` and `pattern:]`, we had to escape a slash for the closing tag `pattern:[\/\1]`, because normally the slash closes the pattern. +Tenga en cuenta que además de escapar `pattern:[` y `pattern:]`, tuvimos que escapar de una barra para la etiqueta de cierre `pattern:[\/\1]`, porque normalmente la barra cierra el patrón. diff --git a/9-regular-expressions/13-regexp-alternation/02-find-matching-bbtags/task.md b/9-regular-expressions/13-regexp-alternation/02-find-matching-bbtags/task.md index 72d715afd..c0d116341 100644 --- a/9-regular-expressions/13-regexp-alternation/02-find-matching-bbtags/task.md +++ b/9-regular-expressions/13-regexp-alternation/02-find-matching-bbtags/task.md @@ -1,25 +1,25 @@ -# Find bbtag pairs +# Encuentra la pareja bbtag -A "bb-tag" looks like `[tag]...[/tag]`, where `tag` is one of: `b`, `url` or `quote`. +Un "bb-tag" se ve como `[tag]...[/tag]`, donde `tag` es uno de: `b`, `url` o `quote`. -For instance: +Por ejemplo: ``` [b]text[/b] [url]http://google.com[/url] ``` -BB-tags can be nested. But a tag can't be nested into itself, for instance: +BB-tags se puede anidar. Pero una etiqueta no se puede anidar en sí misma, por ejemplo: ``` Normal: [url] [b]http://google.com[/b] [/url] [quote] [b]text[/b] [/quote] -Can't happen: +No puede suceder: [b][b]text[/b][/b] ``` -Tags can contain line breaks, that's normal: +Las etiquetas pueden contener saltos de línea, eso es normal: ``` [quote] @@ -27,9 +27,9 @@ Tags can contain line breaks, that's normal: [/quote] ``` -Create a regexp to find all BB-tags with their contents. +Cree una expresión regular para encontrar todas las BB-tags con su contenido. -For instance: +Por ejemplo: ```js let regexp = /your regexp/flags; @@ -38,7 +38,7 @@ let str = "..[url]http://google.com[/url].."; alert( str.match(regexp) ); // [url]http://google.com[/url] ``` -If tags are nested, then we need the outer tag (if we want we can continue the search in its content): +Si las etiquetas están anidadas, entonces necesitamos la etiqueta externa (si queremos podemos continuar la búsqueda en su contenido): ```js let regexp = /your regexp/flags; diff --git a/9-regular-expressions/13-regexp-alternation/03-match-quoted-string/solution.md b/9-regular-expressions/13-regexp-alternation/03-match-quoted-string/solution.md index 5a007aee0..42174470b 100644 --- a/9-regular-expressions/13-regexp-alternation/03-match-quoted-string/solution.md +++ b/9-regular-expressions/13-regexp-alternation/03-match-quoted-string/solution.md @@ -1,13 +1,13 @@ -The solution: `pattern:/"(\\.|[^"\\])*"/g`. +La solución: `pattern:/"(\\.|[^"\\])*"/g`. -Step by step: +El paso a paso: -- First we look for an opening quote `pattern:"` -- Then if we have a backslash `pattern:\\` (we technically have to double it in the pattern, because it is a special character, so that's a single backslash in fact), then any character is fine after it (a dot). -- Otherwise we take any character except a quote (that would mean the end of the string) and a backslash (to prevent lonely backslashes, the backslash is only used with some other symbol after it): `pattern:[^"\\]` -- ...And so on till the closing quote. +- Primero buscamos una comilla de apertura `pattern:"` +- Entonces, si tenemos una barra invertida `pattern:\\` (tenemos que duplicarla en el patrón porque es un carácter especial), y luego cualquier carácter está bien después de él (un punto). +- De lo contrario, tomamos cualquier carácter excepto una comilla (que significaría el final de la cadena) y una barra invertida (para evitar barras invertidas solitarias, la barra invertida solo se usa con algún otro símbolo después): `pattern:[^"\\]` +- ...Y así sucesivamente hasta la comilla de cierre. -In action: +En acción: ```js run let regexp = /"(\\.|[^"\\])*"/g; diff --git a/9-regular-expressions/13-regexp-alternation/03-match-quoted-string/task.md b/9-regular-expressions/13-regexp-alternation/03-match-quoted-string/task.md index ad41d91b1..0e02b4d2b 100644 --- a/9-regular-expressions/13-regexp-alternation/03-match-quoted-string/task.md +++ b/9-regular-expressions/13-regexp-alternation/03-match-quoted-string/task.md @@ -1,28 +1,28 @@ -# Find quoted strings +# Encuentra cadenas entre comillas -Create a regexp to find strings in double quotes `subject:"..."`. +Crea una expresión regular para encontrar cadenas entre comillas dobles `subject:"..."`. -The strings should support escaping, the same way as JavaScript strings do. For instance, quotes can be inserted as `subject:\"` a newline as `subject:\n`, and the slash itself as `subject:\\`. +Las cadenas deben admitir el escape, de la misma manera que lo hacen las cadenas de JavaScript. Por ejemplo, las comillas se pueden insertar como `subject:\"` ,una nueva línea como `subject:\n`, y la doble barra invertida como `subject:\\`. ```js let str = "Just like \"here\"."; ``` -Please note, in particular, that an escaped quote `subject:\"` does not end a string. +Tenga en cuenta, en particular, que una comilla escapada `subject:\"` no termina una cadena. -So we should search from one quote to the other ignoring escaped quotes on the way. +Por lo tanto, deberíamos buscar de una comilla a otra (la de cierre), ignorando las comillas escapadas en el camino. -That's the essential part of the task, otherwise it would be trivial. +Esa es la parte esencial de la tarea, de lo contrario sería trivial. -Examples of strings to match: +Ejemplos de cadenas para hacer coincidir: ```js .. *!*"test me"*/!* .. -.. *!*"Say \"Hello\"!"*/!* ... (escaped quotes inside) -.. *!*"\\"*/!* .. (double slash inside) -.. *!*"\\ \""*/!* .. (double slash and an escaped quote inside) +.. *!*"Say \"Hello\"!"*/!* ... (comillas escapadas dentro) +.. *!*"\\"*/!* .. (doble barra invertida dentro) +.. *!*"\\ \""*/!* .. (doble barra y comilla escapada dentro.) ``` -In JavaScript we need to double the slashes to pass them right into the string, like this: +En JavaScript, necesitamos duplicar las barras para pasarlas directamente a la cadena, así: ```js run let str = ' .. "test me" .. "Say \\"Hello\\"!" .. "\\\\ \\"" .. '; diff --git a/9-regular-expressions/13-regexp-alternation/04-match-exact-tag/solution.md b/9-regular-expressions/13-regexp-alternation/04-match-exact-tag/solution.md index 5d4ba8d96..4eb6f1ec0 100644 --- a/9-regular-expressions/13-regexp-alternation/04-match-exact-tag/solution.md +++ b/9-regular-expressions/13-regexp-alternation/04-match-exact-tag/solution.md @@ -1,13 +1,13 @@ -The pattern start is obvious: `pattern:`, because `match:` would match it. +...Pero entonces no podemos simplemente escribir `pattern:`, porque `match:` coincidiría. -We need either a space after `match:`. +Necesitamos un espacio después `match:`. -In the regexp language: `pattern:|\s.*?>)`. +En el lenguaje de expresión regular: `pattern:|\s.*?>)`. -In action: +En acción: ```js run let regexp = /|\s.*?>)/g; diff --git a/9-regular-expressions/13-regexp-alternation/04-match-exact-tag/task.md b/9-regular-expressions/13-regexp-alternation/04-match-exact-tag/task.md index e8a9e31b4..7aebda73e 100644 --- a/9-regular-expressions/13-regexp-alternation/04-match-exact-tag/task.md +++ b/9-regular-expressions/13-regexp-alternation/04-match-exact-tag/task.md @@ -1,10 +1,10 @@ -# Find the full tag +# Encuentra la etiqueta completa -Write a regexp to find the tag ``. It should match the full tag: it may have no attributes `