- Notifications
You must be signed in to change notification settings - Fork230
Alternation (OR) |#473
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
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
10 commits Select commitHold shift + click to select a range
b2f0302 regexp or
vplentinaxdf36170 Merge branch 'master' into or
vplentinax1325296 Update 9-regular-expressions/13-regexp-alternation/03-match-quoted-st…
vplentinax3bb53ad Update 9-regular-expressions/13-regexp-alternation/03-match-quoted-st…
vplentinaxbef3bd5 Update 9-regular-expressions/13-regexp-alternation/03-match-quoted-st…
vplentinaxcdbcf15 Update 9-regular-expressions/13-regexp-alternation/03-match-quoted-st…
vplentinax7911a22 Update 9-regular-expressions/13-regexp-alternation/03-match-quoted-st…
vplentinaxee74c4f Update 9-regular-expressions/13-regexp-alternation/01-find-programmin…
joaquinelio3d157e7 Update 9-regular-expressions/13-regexp-alternation/03-match-quoted-st…
joaquinelioeeb7ba4 Update 9-regular-expressions/13-regexp-alternation/01-find-programmin…
joaquinelioFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
18 changes: 9 additions & 9 deletions...ular-expressions/13-regexp-alternation/01-find-programming-language/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
6 changes: 3 additions & 3 deletions9-regular-expressions/13-regexp-alternation/01-find-programming-language/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
10 changes: 5 additions & 5 deletions9-regular-expressions/13-regexp-alternation/02-find-matching-bbtags/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
18 changes: 9 additions & 9 deletions9-regular-expressions/13-regexp-alternation/02-find-matching-bbtags/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
14 changes: 7 additions & 7 deletions9-regular-expressions/13-regexp-alternation/03-match-quoted-string/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
22 changes: 11 additions & 11 deletions9-regular-expressions/13-regexp-alternation/03-match-quoted-string/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
10 changes: 5 additions & 5 deletions9-regular-expressions/13-regexp-alternation/04-match-exact-tag/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
8 changes: 4 additions & 4 deletions9-regular-expressions/13-regexp-alternation/04-match-exact-tag/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
60 changes: 30 additions & 30 deletions9-regular-expressions/13-regexp-alternation/article.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,67 +1,67 @@ | ||
| #Altarnancia (OR (O)) | | ||
joaquinelio marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| Alternancia es un término en expresiónregularque simplemente significa "O". | ||
| En una expresiónregularse denota con un carácter de línea vertical`pattern:|`. | ||
| Por ejemplo, necesitamos encontrar lenguajes de programación: HTML, PHP, Javao JavaScript. | ||
| La expresión regular correspondiente es:`pattern:html|php|java(script)?`. | ||
| Un ejemplo de uso: | ||
| ```js run | ||
| let regexp=/html|php|css|java(script)?/gi; | ||
| let str="Primera aparición de HTML, luego CSS,luego JavaScript"; | ||
| alert(str.match(regexp) );// 'HTML', 'CSS', 'JavaScript' | ||
| ``` | ||
| Ya vimos algosimilar: corchetes. Permiten elegir entre varios caracteres, por ejemplo`pattern:gr[ae]y`coincide con`match:gray`o`match:grey`. | ||
| Los corchetes solo permiten caracteres o conjuntos de caracteres. La alternancia permite cualquier expresión. Una expresión regular`pattern:A|B|C`significa una de las expresiones`A`,`B`o`C`. | ||
| Por ejemplo: | ||
| -`pattern:gr(a|e)y`significa exactamente lo mismo que`pattern:gr[ae]y`. | ||
| -`pattern:gra|ey`significa`match:gra`o`match:ey`. | ||
| Para aplicar la alternancia auna parte elegida del patrón, podemos encerrarla entre paréntesis: | ||
| -`pattern:I love HTML|CSS`coincide con`match:I love HTML`o`match:CSS`. | ||
| -`pattern:I love (HTML|CSS)`coincide con`match:I love HTML`o`match:I love CSS`. | ||
| ##Ejemplo: Expresión regular para el tiempo | ||
| En artículos anteriores había una tarea para construir una expresión regular para buscar un horario en la forma`hh:mm`,por ejemplo`12:00`.Pero esta simpleexpresión`pattern:\d\d:\d\d`es muy vaga. Acepta`25:99`como tiempo (ya que99segundos coinciden con el patrón, pero ese tiempo no es válido). | ||
| ¿Cómo podemos hacer un mejor patrón? | ||
| Podemos utilizar una combinación más cuidadosa. Primero, las horas: | ||
| -Si el primer dígito es`0`o`1`,entonces el siguiente dígito puede ser cualquiera:`pattern:[01]\d`. | ||
| -De otra manera, si el primer dígito es`2`,entonces el siguiente debe ser`pattern:[0-3]`. | ||
| - (nose permite ningún otro dígito) | ||
| Podemos escribir ambas variantes en una expresión regular usando alternancia:`pattern:[01]\d|2[0-3]`. | ||
| A continuación, los minutos deben estar comprendidos entre`00`y`59`.En el lenguaje de expresiones regulares que se puede escribir como`pattern:[0-5]\d`:el primer dígito`0-5`,y luego culquier otro. | ||
| Si pegamos minutos y segundos juntos, obtenemos el patrón:`pattern:[01]\d|2[0-3]:[0-5]\d`. | ||
| Ya casi terminamos, pero hay un problema. La alternancia`pattern:|`ahora pasa a estar entre`pattern:[01]\d`y`pattern:2[0-3]:[0-5]\d`. | ||
| Es decir: se agregan minutos a la segunda variante de alternancia, aquí hay una imagen clara: | ||
| ``` | ||
| [01]\d | 2[0-3]:[0-5]\d | ||
| ``` | ||
| Este patrón busca`pattern:[01]\d`o`pattern:2[0-3]:[0-5]\d`. | ||
| Pero eso es incorrecto, la alternancia solo debe usarse en la parte "horas" de la expresión regular, para permitir`pattern:[01]\d`O`pattern:2[0-3]`.Corregiremos eso encerrando las "horas" entre paréntesis:`pattern:([01]\d|2[0-3]):[0-5]\d`. | ||
| La soluciónfinalsería: | ||
| ```js run | ||
| let regexp=/([01]\d|2[0-3]):[0-5]\d/g; | ||
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.