-
Notifications
You must be signed in to change notification settings - Fork 228
Greedy and lazy quantifiers #355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
joaquinelio
merged 10 commits into
javascript-tutorial:master
from
cortizg:es.javascript.info.9-10-glq
Aug 30, 2020
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b88371c
traducción 9-10-glq
cortizg b93e3da
Update 9-regular-expressions/10-regexp-greedy-and-lazy/article.md
cortizg 4f36e0c
Update 9-regular-expressions/10-regexp-greedy-and-lazy/article.md
cortizg e1987f3
Update 9-regular-expressions/10-regexp-greedy-and-lazy/4-find-html-ta…
cortizg 4b80bdc
Update 9-regular-expressions/10-regexp-greedy-and-lazy/4-find-html-ta…
cortizg a077326
Update 9-regular-expressions/10-regexp-greedy-and-lazy/4-find-html-ta…
cortizg 920e596
Update 9-regular-expressions/10-regexp-greedy-and-lazy/4-find-html-ta…
cortizg f4883c3
Update 9-regular-expressions/10-regexp-greedy-and-lazy/article.md
cortizg 4b5b44d
Update 9-regular-expressions/10-regexp-greedy-and-lazy/article.md
cortizg fb7a0c4
Update 9-regular-expressions/10-regexp-greedy-and-lazy/article.md
cortizg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
9-regular-expressions/10-regexp-greedy-and-lazy/1-lazy-greedy/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
|
||
The result is: `match:123 4`. | ||
El resultado es: `match:123 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`. | ||
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`. | ||
|
||
Then the second `\d+?` takes only one digit, because that's enough. | ||
Después el segundo `\d+?` toma solo un dígito, porque es sufuciente. |
4 changes: 2 additions & 2 deletions
4
9-regular-expressions/10-regexp-greedy-and-lazy/1-lazy-greedy/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
9-regular-expressions/10-regexp-greedy-and-lazy/3-find-html-comments/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
We need to find the beginning of the comment `match:<!--`, then everything till the end of `match:-->`. | ||
Necesitamos encontrar el inicio del comentario `match:<!--`, después todo hasta el fin de `match:-->`. | ||
|
||
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. | ||
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. | ||
|
||
Otherwise multiline comments won't be found: | ||
De lo contrario, no se encontrarán comentarios multilínea: | ||
|
||
```js run | ||
let regexp = /<!--.*?-->/gs; | ||
|
||
let str = `... <!-- My -- comment | ||
test --> .. <!----> .. | ||
let str = `... <!-- Mi -- comentario | ||
prueba --> .. <!----> .. | ||
`; | ||
|
||
alert( str.match(regexp) ); // '<!-- My -- comment \n test -->', '<!---->' | ||
alert( str.match(regexp) ); // '<!-- Mi -- comentario \n prueba -->', '<!---->' | ||
``` |
10 changes: 5 additions & 5 deletions
10
9-regular-expressions/10-regexp-greedy-and-lazy/3-find-html-comments/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
# Find HTML comments | ||
# Encuentra el comentario HTML | ||
|
||
Find all HTML comments in the text: | ||
Encuentra todos los comentarios HTML en el texto: | ||
|
||
```js | ||
let regexp = /your regexp/g; | ||
|
||
let str = `... <!-- My -- comment | ||
test --> .. <!----> .. | ||
let str = `... <!-- Mi -- comentario | ||
prueba --> .. <!----> .. | ||
`; | ||
|
||
alert( str.match(regexp) ); // '<!-- My -- comment \n test -->', '<!---->' | ||
alert( str.match(regexp) ); // '<!-- Mi -- comentario \n prueba -->', '<!---->' | ||
``` |
6 changes: 3 additions & 3 deletions
6
...-expressions/10-regexp-greedy-and-lazy/4-find-html-tags-greedy-lazy/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
|
||
The solution is `pattern:<[^<>]+>`. | ||
La solución es `pattern:<[^<>]+>`. | ||
|
||
```js run | ||
let regexp = /<[^<>]+>/g; | ||
|
||
let str = '<> <a href="/"> <input type="radio" checked> <b>'; | ||
let str = '<> <a href="/"> <input type="radio" comprobado> <b>'; | ||
|
||
alert( str.match(regexp) ); // '<a href="/">', '<input type="radio" checked>', '<b>' | ||
alert( str.match(regexp) ); // '<a href="/">', '<input type="radio" comprobado>', '<b>' | ||
cortizg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` |
14 changes: 7 additions & 7 deletions
14
...ular-expressions/10-regexp-greedy-and-lazy/4-find-html-tags-greedy-lazy/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
# Find HTML tags | ||
# Encontrar las etiquetas HTML | ||
|
||
Create a regular expression to find all (opening and closing) HTML tags with their attributes. | ||
Crear una expresión regular para encontrar todas las etiquetas HTML (de apertura y cierre) con sus atributos. | ||
|
||
An example of use: | ||
Un ejemplo de uso: | ||
|
||
```js run | ||
let regexp = /your regexp/g; | ||
let regexp = /tu regexp/g; | ||
|
||
let str = '<> <a href="/"> <input type="radio" checked> <b>'; | ||
let str = '<> <a href="/"> <input type="radio" comprobado> <b>'; | ||
cortizg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
alert( str.match(regexp) ); // '<a href="/">', '<input type="radio" checked>', '<b>' | ||
alert( str.match(regexp) ); // '<a href="/">', '<input type="radio" comprobado>', '<b>' | ||
cortizg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
Here we assume that tag attributes may not contain `<` and `>` (inside squotes too), that simplifies things a bit. | ||
Asumimos que los atributos de etiqueta no deben contener `<` ni `>` (dentro de comillas dobles también), esto simplifica un poco las cosas. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.