mirror of
https://github.com/ziishaned/learn-regex.git
synced 2025-09-29 23:30:32 -04:00
translating titles
This commit is contained in:
parent
240ad07ce2
commit
50ec9a07e8
132
README-pt_BR.md
132
README-pt_BR.md
@ -25,37 +25,37 @@ Imagine que você está escrevendo uma aplicação e quer colocar regras para qu
|
||||
|
||||
A expressão regular acima aceita as strings `john_doe`, `jo-hn_doe` e `john12_as`. Ela não aceita `Jo` porque essa string contém letras maiúsculas e também é muito curta.
|
||||
|
||||
## Table of Contents
|
||||
## Sumário
|
||||
|
||||
- [Basic Matchers](#1-basic-matchers)
|
||||
- [Meta character](#2-meta-characters)
|
||||
- [Full stop](#21-full-stop)
|
||||
- [Character set](#22-character-set)
|
||||
- [Negated character set](#221-negated-character-set)
|
||||
- [Repetitions](#23-repetitions)
|
||||
- [The Star](#231-the-star)
|
||||
- [The Plus](#232-the-plus)
|
||||
- [The Question Mark](#233-the-question-mark)
|
||||
- [Braces](#24-braces)
|
||||
- [Character Group](#25-character-group)
|
||||
- [Alternation](#26-alternation)
|
||||
- [Escaping special character](#27-escaping-special-character)
|
||||
- [Anchors](#28-anchors)
|
||||
- [Caret](#281-caret)
|
||||
- [Dollar](#282-dollar)
|
||||
- [Shorthand Character Sets](#3-shorthand-character-sets)
|
||||
- [Lookaround](#4-lookaround)
|
||||
- [Positive Lookahead](#41-positive-lookahead)
|
||||
- [Negative Lookahead](#42-negative-lookahead)
|
||||
- [Positive Lookbehind](#43-positive-lookbehind)
|
||||
- [Negative Lookbehind](#44-negative-lookbehind)
|
||||
- [Combinações Básicas](#1-basic-matchers)
|
||||
- [Metacaracteres](#2-meta-characters)
|
||||
- [Ponto final](#21-full-stop)
|
||||
- [Conjunto de caracteres](#22-character-set)
|
||||
- [Conjunto de caracteres negados](#221-negated-character-set)
|
||||
- [Repetições](#23-repetitions)
|
||||
- [O Asterisco](#231-the-star)
|
||||
- [O Sinal de Adição](#232-the-plus)
|
||||
- [O Ponto de Interrogação](#233-the-question-mark)
|
||||
- [Chaves](#24-braces)
|
||||
- [Grupo de Caracteres](#25-character-group)
|
||||
- [Alternância](#26-alternation)
|
||||
- [Escapando Caracteres Especiais](#27-escaping-special-character)
|
||||
- [Âncoras](#28-anchors)
|
||||
- [Acento Circunflexo](#281-caret)
|
||||
- [Sinal de Dólar](#282-dollar)
|
||||
- [Forma Abreviada de Conjunto de Caracteres](#3-shorthand-character-sets)
|
||||
- [Olhar ao Redor](#4-lookaround)
|
||||
- [Lookahead Positivo](#41-positive-lookahead)
|
||||
- [Lookahead Negativo](#42-negative-lookahead)
|
||||
- [Lookbehind Positivo](#43-positive-lookbehind)
|
||||
- [Lookbehind Negativo](#44-negative-lookbehind)
|
||||
- [Flags](#5-flags)
|
||||
- [Case Insensitive](#51-case-insensitive)
|
||||
- [Global search](#52-global-search)
|
||||
- [Multiline](#53-multiline)
|
||||
- [Bonus](#bonus)
|
||||
- [Indiferente à Maiúsculas](#51-case-insensitive)
|
||||
- [Busca Global](#52-global-search)
|
||||
- [Multilinhas](#53-multiline)
|
||||
- [Bônus](#bonus)
|
||||
|
||||
## 1. Basic Matchers
|
||||
## 1. Combinações Básicas
|
||||
|
||||
A regular expression is just a pattern of characters that we use to perform search in a text. For example, the regular expression
|
||||
`the` means: the letter `t`, followed by the letter `h`, followed by the letter `e`.
|
||||
@ -76,7 +76,7 @@ case-sensitive so the regular expression `The` would not match the string `the`.
|
||||
|
||||
[Test the regular expression](https://regex101.com/r/1paXsy/1)
|
||||
|
||||
## 2. Meta Characters
|
||||
## 2. Metacaracteres
|
||||
|
||||
Meta characters are the building blocks of the regular expressions. Meta characters do not stand for themselves but instead are
|
||||
interpreted in some special way. Some meta characters have a special meaning and are written inside square brackets.
|
||||
@ -90,16 +90,16 @@ The meta characters are as follows:
|
||||
|*|Matches 0 or more repetitions of the preceding symbol.|
|
||||
|+|Matches 1 or more repetitions of the preceding symbol.
|
||||
|?|Makes the preceding symbol optional.|
|
||||
|{n,m}|Braces. Matches at least "n" but not more than "m" repetitions of the preceding symbol.|
|
||||
|{n,m}|Chaves. Matches at least "n" but not more than "m" repetitions of the preceding symbol.|
|
||||
|(xyz)|Character group. Matches the characters xyz in that exact order.|
|
||||
|||Alternation. Matches either the characters before or the characters after the symbol.|
|
||||
|||Alternância. Matches either the characters before or the characters after the symbol.|
|
||||
|\|Escapes the next character. This allows you to match reserved characters <code>[ ] ( ) { } . * + ? ^ $ \ |</code>|
|
||||
|^|Matches the beginning of the input.|
|
||||
|$|Matches the end of the input.|
|
||||
|
||||
## 2.1 Full stop
|
||||
## 2.1 Ponto final
|
||||
|
||||
Full stop `.` is the simplest example of meta character. The meta character `.` matches any single character. It will not match return
|
||||
Ponto final `.` is the simplest example of meta character. The meta character `.` matches any single character. It will not match return
|
||||
or newline characters. For example, the regular expression `.ar` means: any character, followed by the letter `a`, followed by the
|
||||
letter `r`.
|
||||
|
||||
@ -109,7 +109,7 @@ letter `r`.
|
||||
|
||||
[Test the regular expression](https://regex101.com/r/xc9GkU/1)
|
||||
|
||||
## 2.2 Character set
|
||||
## 2.2 Conjunto de caracteres
|
||||
|
||||
Character sets are also called character class. Square brackets are used to specify character sets. Use a hyphen inside a character set to
|
||||
specify the characters' range. The order of the character range inside square brackets doesn't matter. For example, the regular
|
||||
@ -129,7 +129,7 @@ A period inside a character set, however, means a literal period. The regular ex
|
||||
|
||||
[Test the regular expression](https://regex101.com/r/wL3xtE/1)
|
||||
|
||||
### 2.2.1 Negated character set
|
||||
### 2.2.1 Conjunto de caracteres negados
|
||||
|
||||
In general, the caret symbol represents the start of the string, but when it is typed after the opening square bracket it negates the
|
||||
character set. For example, the regular expression `[^c]ar` means: any character except `c`, followed by the character `a`, followed by
|
||||
@ -141,12 +141,12 @@ the letter `r`.
|
||||
|
||||
[Test the regular expression](https://regex101.com/r/nNNlq3/1)
|
||||
|
||||
## 2.3 Repetitions
|
||||
## 2.3 Repetições
|
||||
|
||||
Following meta characters `+`, `*` or `?` are used to specify how many times a subpattern can occur. These meta characters act
|
||||
differently in different situations.
|
||||
|
||||
### 2.3.1 The Star
|
||||
### 2.3.1 O Asterisco
|
||||
|
||||
The symbol `*` matches zero or more repetitions of the preceding matcher. The regular expression `a*` means: zero or more repetitions
|
||||
of preceding lowercase character `a`. But if it appears after a character set or class then it finds the repetitions of the whole
|
||||
@ -169,7 +169,7 @@ zero or more spaces.
|
||||
|
||||
[Test the regular expression](https://regex101.com/r/gGrwuz/1)
|
||||
|
||||
### 2.3.2 The Plus
|
||||
### 2.3.2 O Sinal de Adição
|
||||
|
||||
The symbol `+` matches one or more repetitions of the preceding character. For example, the regular expression `c.+t` means: lowercase
|
||||
letter `c`, followed by at least one character, followed by the lowercase character `t`.
|
||||
@ -180,7 +180,7 @@ letter `c`, followed by at least one character, followed by the lowercase charac
|
||||
|
||||
[Test the regular expression](https://regex101.com/r/Dzf9Aa/1)
|
||||
|
||||
### 2.3.3 The Question Mark
|
||||
### 2.3.3 O Ponto de Interrogação
|
||||
|
||||
In regular expression the meta character `?` makes the preceding character optional. This symbol matches zero or one instance of
|
||||
the preceding character. For example, the regular expression `[T]?he` means: Optional the uppercase letter `T`, followed by the lowercase
|
||||
@ -198,7 +198,7 @@ character `h`, followed by the lowercase character `e`.
|
||||
|
||||
[Test the regular expression](https://regex101.com/r/kPpO2x/1)
|
||||
|
||||
## 2.4 Braces
|
||||
## 2.4 Chaves
|
||||
|
||||
In regular expression braces that are also called quantifiers are used to specify the number of times that a
|
||||
character or a group of characters can be repeated. For example, the regular expression `[0-9]{2,3}` means: Match at least 2 digits but not more than 3 (
|
||||
@ -225,7 +225,7 @@ the comma the regular expression `[0-9]{3}` means: Match exactly 3 digits.
|
||||
|
||||
[Test the regular expression](https://regex101.com/r/Sivu30/1)
|
||||
|
||||
## 2.5 Character Group
|
||||
## 2.5 Grupo de Caracteres
|
||||
|
||||
Character group is a group of sub-patterns that is written inside Parentheses `(...)`. As we discussed before that in regular expression
|
||||
if we put a quantifier after a character then it will repeat the preceding character. But if we put quantifier after a character group then
|
||||
@ -239,7 +239,7 @@ We can also use the alternation `|` meta character inside character group. For e
|
||||
|
||||
[Test the regular expression](https://regex101.com/r/tUxrBG/1)
|
||||
|
||||
## 2.6 Alternation
|
||||
## 2.6 Alternância
|
||||
|
||||
In regular expression Vertical bar `|` is used to define alternation. Alternation is like a condition between multiple expressions. Now,
|
||||
you may be thinking that character set and alternation works the same way. But the big difference between character set and alternation
|
||||
@ -253,7 +253,7 @@ or lowercase character `c`, followed by lowercase character `a`, followed by low
|
||||
|
||||
[Test the regular expression](https://regex101.com/r/fBXyX0/1)
|
||||
|
||||
## 2.7 Escaping special character
|
||||
## 2.7 Escapando Caracteres Especiais
|
||||
|
||||
Backslash `\` is used in regular expression to escape the next character. This allows to to specify a symbol as a matching character
|
||||
including reserved characters `{ } [ ] / \ + * . $ ^ | ?`. To use a special character as a matching character prepend `\` before it.
|
||||
@ -267,16 +267,16 @@ expression `(f|c|m)at\.?` means: lowercase letter `f`, `c` or `m`, followed by l
|
||||
|
||||
[Test the regular expression](https://regex101.com/r/DOc5Nu/1)
|
||||
|
||||
## 2.8 Anchors
|
||||
## 2.8 Âncoras
|
||||
|
||||
In regular expressions, we use anchors to check if the matching symbol is the starting symbol or ending symbol of the
|
||||
input string. Anchors are of two types: First type is Caret `^` that check if the matching character is the start
|
||||
character of the input and the second type is Dollar `$` that checks if matching character is the last character of the
|
||||
input string. Âncoras are of two types: First type is Acento Circunflexo `^` that check if the matching character is the start
|
||||
character of the input and the second type is Sinal de Dólar `$` that checks if matching character is the last character of the
|
||||
input string.
|
||||
|
||||
### 2.8.1 Caret
|
||||
### 2.8.1 Acento Circunflexo
|
||||
|
||||
Caret `^` symbol is used to check if matching character is the first character of the input string. If we apply the following regular
|
||||
Acento Circunflexo `^` symbol is used to check if matching character is the first character of the input string. If we apply the following regular
|
||||
expression `^a` (if a is the starting symbol) to input string `abc` it matches `a`. But if we apply regular expression `^b` on above
|
||||
input string it does not match anything. Because in input string `abc` "b" is not the starting symbol. Let's take a look at another
|
||||
regular expression `^(T|t)he` which means: uppercase character `T` or lowercase character `t` is the start symbol of the input string,
|
||||
@ -294,9 +294,9 @@ followed by lowercase character `h`, followed by lowercase character `e`.
|
||||
|
||||
[Test the regular expression](https://regex101.com/r/jXrKne/1)
|
||||
|
||||
### 2.8.2 Dollar
|
||||
### 2.8.2 Sinal de Dólar
|
||||
|
||||
Dollar `$` symbol is used to check if matching character is the last character of the input string. For example, regular expression
|
||||
Sinal de Dólar `$` symbol is used to check if matching character is the last character of the input string. For example, regular expression
|
||||
`(at\.)$` means: a lowercase character `a`, followed by lowercase character `t`, followed by a `.` character and the matcher
|
||||
must be end of the string.
|
||||
|
||||
@ -312,7 +312,7 @@ must be end of the string.
|
||||
|
||||
[Test the regular expression](https://regex101.com/r/t0AkOd/1)
|
||||
|
||||
## 3. Shorthand Character Sets
|
||||
## 3. Forma Abreviada de Conjunto de Caracteres
|
||||
|
||||
Regular expression provides shorthands for the commonly used character sets, which offer convenient shorthands for commonly used
|
||||
regular expressions. The shorthand character sets are as follows:
|
||||
@ -327,7 +327,7 @@ regular expressions. The shorthand character sets are as follows:
|
||||
|\s|Matches whitespace character: `[\t\n\f\r\p{Z}]`|
|
||||
|\S|Matches non-whitespace character: `[^\s]`|
|
||||
|
||||
## 4. Lookaround
|
||||
## 4. Olhar ao Redor
|
||||
|
||||
Lookbehind and lookahead sometimes known as lookaround are specific type of ***non-capturing group*** (Use to match the pattern but not
|
||||
included in matching list). Lookaheads are used when we have the condition that this pattern is preceded or followed by another certain
|
||||
@ -337,12 +337,12 @@ by `$` character. Following are the lookarounds that are used in regular express
|
||||
|
||||
|Symbol|Description|
|
||||
|:----:|----|
|
||||
|?=|Positive Lookahead|
|
||||
|?!|Negative Lookahead|
|
||||
|?<=|Positive Lookbehind|
|
||||
|?<!|Negative Lookbehind|
|
||||
|?=|Lookahead Positivo|
|
||||
|?!|Lookahead Negativo|
|
||||
|?<=|Lookbehind Positivo|
|
||||
|?<!|Lookbehind Negativo|
|
||||
|
||||
### 4.1 Positive Lookahead
|
||||
### 4.1 Lookahead Positivo
|
||||
|
||||
The positive lookahead asserts that the first part of the expression must be followed by the lookahead expression. The returned match
|
||||
only contains the text that is matched by the first part of the expression. To define a positive lookahead, parentheses are used. Within
|
||||
@ -357,7 +357,7 @@ followed by letter `h`, followed by letter `e`. In parentheses we define positiv
|
||||
|
||||
[Test the regular expression](https://regex101.com/r/IDDARt/1)
|
||||
|
||||
### 4.2 Negative Lookahead
|
||||
### 4.2 Lookahead Negativo
|
||||
|
||||
Negative lookahead is used when we need to get all matches from input string that are not followed by a pattern. Negative lookahead
|
||||
defined same as we define positive lookahead but the only difference is instead of equal `=` character we use negation `!` character
|
||||
@ -370,7 +370,7 @@ input string that are not followed by the word `fat` precedes by a space charact
|
||||
|
||||
[Test the regular expression](https://regex101.com/r/V32Npg/1)
|
||||
|
||||
### 4.3 Positive Lookbehind
|
||||
### 4.3 Lookbehind Positivo
|
||||
|
||||
Positive lookbehind is used to get all the matches that are preceded by a specific pattern. Positive lookbehind is denoted by
|
||||
`(?<=...)`. For example, the regular expression `(?<=[T|t]he\s)(fat|mat)` means: get all `fat` or `mat` words from input string that
|
||||
@ -382,7 +382,7 @@ are after the word `The` or `the`.
|
||||
|
||||
[Test the regular expression](https://regex101.com/r/avH165/1)
|
||||
|
||||
### 4.4 Negative Lookbehind
|
||||
### 4.4 Lookbehind Negativo
|
||||
|
||||
Negative lookbehind is used to get all the matches that are not preceded by a specific pattern. Negative lookbehind is denoted by
|
||||
`(?<!...)`. For example, the regular expression `(?<!(T|t)he\s)(cat)` means: get all `cat` words from input string that
|
||||
@ -396,16 +396,16 @@ are not after the word `The` or `the`.
|
||||
|
||||
## 5. Flags
|
||||
|
||||
Flags are also called modifiers because they modify the output of a regular expression. These flags can be used in any order or
|
||||
Flags (sinalizadores) are also called modifiers because they modify the output of a regular expression. These flags can be used in any order or
|
||||
combination, and are an integral part of the RegExp.
|
||||
|
||||
|Flag|Description|
|
||||
|:----:|----|
|
||||
|i|Case insensitive: Sets matching to be case-insensitive.|
|
||||
|g|Global Search: Search for a pattern throughout the input string.|
|
||||
|m|Multiline: Anchor meta character works on each line.|
|
||||
|m|Multilinhas: Anchor meta character works on each line.|
|
||||
|
||||
### 5.1 Case Insensitive
|
||||
### 5.1 Indiferente à Maiúsculas
|
||||
|
||||
The `i` modifier is used to perform case-insensitive matching. For example, the regular expression `/The/gi` means: uppercase letter
|
||||
`T`, followed by lowercase character `h`, followed by character `e`. And at the end of regular expression the `i` flag tells the
|
||||
@ -424,7 +424,7 @@ the whole input string.
|
||||
|
||||
[Test the regular expression](https://regex101.com/r/ahfiuh/1)
|
||||
|
||||
### 5.2 Global search
|
||||
### 5.2 Busca Global
|
||||
|
||||
The `g` modifier is used to perform a global match (find all matches rather than stopping after the first match). For example, the
|
||||
regular expression`/.(at)/g` means: any character except new line, followed by lowercase character `a`, followed by lowercase
|
||||
@ -443,7 +443,7 @@ string.
|
||||
|
||||
[Test the regular expression](https://regex101.com/r/dO1nef/1)
|
||||
|
||||
### 5.3 Multiline
|
||||
### 5.3 Multilinhas
|
||||
|
||||
The `m` modifier is used to perform a multi-line match. As we discussed earlier anchors `(^, $)` are used to check if pattern is
|
||||
the beginning of the input or end of the input string. But if we want that anchors works on each line we use `m` flag. For example, the
|
||||
@ -466,7 +466,7 @@ line. And because of `m` flag now regular expression engine matches pattern at t
|
||||
|
||||
[Test the regular expression](https://regex101.com/r/E88WE2/1)
|
||||
|
||||
## Bonus
|
||||
## Bônus
|
||||
|
||||
* *Positive Integers*: `^\d+$`
|
||||
* *Negative Integers*: `^-\d+$`
|
||||
|
Loading…
x
Reference in New Issue
Block a user