Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
joaquinelio merged 10 commits intojavascript-tutorial:masterfromcortizg:es.javascript.info.9-10-glq
Aug 30, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
10 commits
Select commitHold shift + click to select a range
b88371c
traducción 9-10-glq
cortizgJul 19, 2020
b93e3da
Update 9-regular-expressions/10-regexp-greedy-and-lazy/article.md
cortizgAug 23, 2020
4f36e0c
Update 9-regular-expressions/10-regexp-greedy-and-lazy/article.md
cortizgAug 23, 2020
e1987f3
Update 9-regular-expressions/10-regexp-greedy-and-lazy/4-find-html-ta…
cortizgAug 23, 2020
4b80bdc
Update 9-regular-expressions/10-regexp-greedy-and-lazy/4-find-html-ta…
cortizgAug 23, 2020
a077326
Update 9-regular-expressions/10-regexp-greedy-and-lazy/4-find-html-ta…
cortizgAug 23, 2020
920e596
Update 9-regular-expressions/10-regexp-greedy-and-lazy/4-find-html-ta…
cortizgAug 23, 2020
f4883c3
Update 9-regular-expressions/10-regexp-greedy-and-lazy/article.md
cortizgAug 23, 2020
4b5b44d
Update 9-regular-expressions/10-regexp-greedy-and-lazy/article.md
cortizgAug 23, 2020
fb7a0c4
Update 9-regular-expressions/10-regexp-greedy-and-lazy/article.md
cortizgAug 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff 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.
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
#A match for /d+? d+?/
#Una coincidencia para /d+? d+?/

What's the match here?
¿Cual es la coincidencia aquí?

```js
"123 456".match(/\d+? \d+?/g) ); // ?
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff 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 \ntest -->', '<!---->'
alert( str.match(regexp) ); // '<!--Mi --comentario \nprueba -->', '<!---->'
```
View file
Open in desktop
Original file line numberDiff line numberDiff 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 \ntest -->', '<!---->'
alert( str.match(regexp) ); // '<!--Mi --comentario \nprueba -->', '<!---->'
```
View file
Open in desktop
Original file line numberDiff line numberDiff 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" checked> <b>';

alert( str.match(regexp) ); // '<a href="/">', '<input type="radio" checked>', '<b>'
alert( str.match(regexp) ); // '<a href="/">', '<input type="radio" checked>', '<b>'
```
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
#Find HTML tags
#Encontrar las etiquetas HTML

Create aregularexpression to find all (opening and closing) HTML tags with their attributes.
Crear una expresiónregularpara 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" checked> <b>';

alert( str.match(regexp) ); // '<a href="/">', '<input type="radio" checked>', '<b>'
alert( str.match(regexp) ); // '<a href="/">', '<input type="radio" checked>', '<b>'
```

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

[8]ページ先頭

©2009-2025 Movatter.jp