- Notifications
You must be signed in to change notification settings - Fork111
Word boundary: \b#424
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
4 commits Select commitHold shift + click to select a range
File 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
5 changes: 2 additions & 3 deletions9-regular-expressions/06-regexp-boundary/1-find-time-hh-mm/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,5 @@ | ||
A resposta: `pattern:\b\d\d:\d\d\b`. | ||
```js run | ||
alert( "Café da manhã as09:00no quarto 123:456.".match( /\b\d\d:\d\d\b/ ) ); // 09:00 | ||
``` |
10 changes: 5 additions & 5 deletions9-regular-expressions/06-regexp-boundary/1-find-time-hh-mm/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,9 +1,9 @@ | ||
#Encontre o horário | ||
Um horário possui o formato `hours:minutes`.Ambas as horas e os minutos possuem dois dígitos, como `09:00`. | ||
Componha uma expressão regular que encontra o horário nastring: `subject:Café da manhã as09:00no quarto 123:456.` | ||
P.S.Nessa tarefa não é necessário verificar a corretude do horário ainda, então `25:99`também pode ser um resultado válido. | ||
peruibeloko marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
P.P.S.A expressão não deve corresponder com `123:456`. |
42 changes: 21 additions & 21 deletions9-regular-expressions/06-regexp-boundary/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,52 +1,52 @@ | ||
#Borda de palavra: \b | ||
Uma borda de palavra`pattern:\b`é um teste, como o `pattern:^`e `pattern:$` também são. | ||
Quando o interpretador de regex (um módulo de programa que implementa a busca por expressões regulares) encontra um `pattern:\b`,ele verifica se naquela posição dastringocorre aborda de uma palavra. | ||
Existem três diferentes posições que configuram uma borda de palavra: | ||
-O início de uma string, se o primeiro caractere dastringé um caractere de palavra `pattern:\w`. | ||
-Entre dois caracteres de uma string,quando um deles é um caractere de palavra`pattern:\w`e o outro não. | ||
-No fim da string, Se o último caractere for um caractere de palavra `pattern:\w`. | ||
Por exemplo, a regex`pattern:\bJava\b`corresponde com`subject:Hello, Java!`,já que`subject:Java`é uma palavra solta, mas não corresponde com `subject:Hello, JavaScript!`. | ||
```js run | ||
alert( "Hello, Java!".match(/\bJava\b/) ); // Java | ||
alert( "Hello, JavaScript!".match(/\bJava\b/) ); // null | ||
``` | ||
Nastring `subject:Hello, Java!`as seguintes posições correspondem ao `pattern:\b`: | ||
 | ||
Ela corresponde com o padrão `pattern:\bHello\b` por que: | ||
1.Corresponde ao começo dastringcom o primeiro teste `pattern:\b`. | ||
2.Depois corresponde com a palavra `pattern:Hello`. | ||
3.E então corresponde com o teste`pattern:\b`novamente, dado que estamos entre um`subject:o`e uma vírgula. | ||
Então o padrão `pattern:\bHello\b`corresponderia, mas não o`pattern:\bHell\b` (porque não temos nenhuma borda de palavra após o`l`), e nem o`Java!\b` (porque a exclamação não é um caractere de palavra `pattern:\w`,então não tem uma borda de palavra após ela). | ||
```js run | ||
alert( "Hello, Java!".match(/\bHello\b/) ); // Hello | ||
alert( "Hello, Java!".match(/\bJava\b/) ); // Java | ||
alert( "Hello, Java!".match(/\bHell\b/) ); // null (nenhuma correspondência) | ||
alert( "Hello, Java!".match(/\bJava!\b/) ); // null (nenhuma correspondência) | ||
``` | ||
Além de usar o`pattern:\b`com palavras, podemos usá-lo com dígitos também. | ||
O padrão`pattern:\b\d\d\b`procura por números soltos de dois dígitos. Em outras palavras, ele procura por números de dois dígitos delimitados por caracteres diferentes da classe`pattern:\w`,como espaços e pontuação (ou início e final da string) | ||
```js run | ||
alert( "1 23 456 78".match(/\b\d\d\b/g) ); // 23,78 | ||
alert( "12,34,56".match(/\b\d\d\b/g) ); // 12,34,56 | ||
``` | ||
```warn header="A borda de palavra`pattern:\b`não funciona com alfabetos não-latinos" | ||
O teste de borda de palavra`pattern:\b`verifica que existe um caractere `pattern:\w`de um lado da posição e um "não `pattern:\w`"do outro | ||
Mas o`pattern:\w`representa uma letra do alfabeto latino`a-z` (ou dígito, ouunderscore '_'),então o teste não funciona para outros alfabetos, como o cirílico ou sinogramas, por exemplo. | ||
``` |
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.