2.8.1 translated

This commit is contained in:
donpepe0 2017-12-17 22:34:54 +01:00
parent ec8c826032
commit a7004852c6

View File

@ -47,19 +47,19 @@ i jest za krótki.
- [Najprostsze wyrażenie](#1-najprostsze-wyrażenie) - [Najprostsze wyrażenie](#1-najprostsze-wyrażenie)
- [Metaznaki](#2-metaznaki) - [Metaznaki](#2-metaznaki)
- [Kropka](#21-kropka) - [Kropka](#21-kropka)
- [Character set](#22-character-set) - [Zestaw znaków](#22-zestaw-znaków)
- [Negated character set](#221-negated-character-set) - [Odwrócony zestaw znaków](#221-odwrócony-zestaw-znaków)
- [Repetitions](#23-repetitions) - [Powtórzenia](#23-powtórzenia)
- [The Star](#231-the-star) - [Gwiazdka](#231-gwiazdka)
- [The Plus](#232-the-plus) - [Plus](#232-plus)
- [The Question Mark](#233-the-question-mark) - [Znak zapytania](#233-znak-zapytania)
- [Braces](#24-braces) - [Klamry](#24-klamry)
- [Character Group](#25-character-group) - [Character Group](#25-character-group)
- [Alternation](#26-alternation) - [Alternatywa](#26-alternatywa)
- [Escaping special character](#27-escaping-special-character) - [Znak ucieczki](#27-znak-ucieczki)
- [Anchors](#28-anchors) - [Kotwice](#28-kotwice)
- [Caret](#281-caret) - [Kareta](#281-kareta)
- [Dollar](#282-dollar) - [Dolar](#282-dolar)
- [Shorthand Character Sets](#3-shorthand-character-sets) - [Shorthand Character Sets](#3-shorthand-character-sets)
- [Lookaround](#4-lookaround) - [Lookaround](#4-lookaround)
- [Positive Lookahead](#41-positive-lookahead) - [Positive Lookahead](#41-positive-lookahead)
@ -112,7 +112,7 @@ Metaznaki to:
|{n,m}|Minimum "n" ale nie więcej niż "m" poprzedzających znaków.| |{n,m}|Minimum "n" ale nie więcej niż "m" poprzedzających znaków.|
|(xyz)|Grupowanie znaków. Znaki xyz dokładnie w tej kolejności.| |(xyz)|Grupowanie znaków. Znaki xyz dokładnie w tej kolejności.|
|||Alternatywa. Znaki przed symbolem lub za symbolem.| |||Alternatywa. Znaki przed symbolem lub za symbolem.|
|&#92;|Znak ucieczki. Umożliwa używanie zarezerwowanych znaków <code>[ ] ( ) { } . * + ? ^ $ \ &#124;</code>| |&#92;|Znak ucieczki. Umożliwa używanie zarezerwowanych znaków <code>[ ] ( ) { } . * + ? ^ $ \ &#124;</code>.|
|^|Oznacza początek wzorca.| |^|Oznacza początek wzorca.|
|$|Oznacza koniec wzorca.| |$|Oznacza koniec wzorca.|
@ -228,12 +228,12 @@ po niej małą literę `h`, następującą po niej małą literę `e`.
[Przetestuj wyrażenie](https://regex101.com/r/kPpO2x/1) [Przetestuj wyrażenie](https://regex101.com/r/kPpO2x/1)
## 2.4 Nawiasy ## 2.4 Klamry
In regular expression braces that are also called quantifiers are used to W wyrażeniach regularnych, klamry zwane również kwantyfikatorami, używane są
specify the number of times that a character or a group of characters can be do określenia, ile razy znak lub grupa znaków może się powtórzyć.
repeated. For example, the regular expression `[0-9]{2,3}` means: Match at least Na przykład wyrażenie regularne `[0-9]{2,3}` oznacza: Przynajmniej
2 digits but not more than 3 ( characters in the range of 0 to 9). 2 znaki, ale nie więcej niż 3 (znaki z zakresu od 0 do 9).
<pre> <pre>
"[0-9]{2,3}" => The number was 9.<a href="#learn-regex"><strong>999</strong></a>7 but we rounded it off to <a href="#learn-regex"><strong>10</strong></a>.0. "[0-9]{2,3}" => The number was 9.<a href="#learn-regex"><strong>999</strong></a>7 but we rounded it off to <a href="#learn-regex"><strong>10</strong></a>.0.
@ -241,9 +241,9 @@ repeated. For example, the regular expression `[0-9]{2,3}` means: Match at least
[Przetestuj wyrażenie](https://regex101.com/r/juM86s/1) [Przetestuj wyrażenie](https://regex101.com/r/juM86s/1)
We can leave out the second number. For example, the regular expression Możemy opuścić drugą liczbę. Na przykład regularne wyrażenie `[0-9]{2,}`
`[0-9]{2,}` means: Match 2 or more digits. If we also remove the comma the oznacza: 2 lub więcej znaków. Jeżeli dodatkowo usuniemy przecinek,
regular expression `[0-9]{3}` means: Match exactly 3 digits. to wyrażenie `[0-9]{3}` oznacza: Dokładnie 3 znaki.
<pre> <pre>
"[0-9]{2,}" => The number was 9.<a href="#learn-regex"><strong>9997</strong></a> but we rounded it off to <a href="#learn-regex"><strong>10</strong></a>.0. "[0-9]{2,}" => The number was 9.<a href="#learn-regex"><strong>9997</strong></a> but we rounded it off to <a href="#learn-regex"><strong>10</strong></a>.0.
@ -257,16 +257,15 @@ regular expression `[0-9]{3}` means: Match exactly 3 digits.
[Przetestuj wyrażenie](https://regex101.com/r/Sivu30/1) [Przetestuj wyrażenie](https://regex101.com/r/Sivu30/1)
## 2.5 Character Group ## 2.5 Grupa znaków
Character group is a group of sub-patterns that is written inside Parentheses `(...)`. Grupa znaków to grupa podwzorców, które zapisywane są w nawiasach `(...)`.
As we discussed before that in regular expression if we put a quantifier after a Jak wspominaliśmy wyżej, jeśli w wyrażeniu regularnym wstawimy kwantyfikator po
character then it will repeat the preceding character. But if we put quantifier znaku, wtedy powtórzy on ten znak. Ale gdy wstawimy kwantyfikator po grupie znaków,
after a character group then it repeats the whole character group. For example, wtedy cała grupa zostanie powtórzona. Na przykład wyrażenie regularne `(ab)*`
the regular expression `(ab)*` matches zero or more repetitions of the character oznacza zero lub więcej powtórzeń grupy "ab". Możemy także użyć metaznaku
"ab". We can also use the alternation `|` meta character inside character group. alternatywy `|` wewnątrz grupy. Na przykład wyrażenie `(c|g|p)ar` oznacza: małą literę `c`,
For example, the regular expression `(c|g|p)ar` means: lowercase character `c`, `g` lub `p`, następującą po niej literę `a`, następującą po niej literę `r`.
`g` or `p`, followed by character `a`, followed by character `r`.
<pre> <pre>
"(c|g|p)ar" => The <a href="#learn-regex"><strong>car</strong></a> is <a href="#learn-regex"><strong>par</strong></a>ked in the <a href="#learn-regex"><strong>gar</strong></a>age. "(c|g|p)ar" => The <a href="#learn-regex"><strong>car</strong></a> is <a href="#learn-regex"><strong>par</strong></a>ked in the <a href="#learn-regex"><strong>gar</strong></a>age.
@ -274,17 +273,15 @@ For example, the regular expression `(c|g|p)ar` means: lowercase character `c`,
[Przetestuj wyrażenie](https://regex101.com/r/tUxrBG/1) [Przetestuj wyrażenie](https://regex101.com/r/tUxrBG/1)
## 2.6 Alternation ## 2.6 Alternatywa
In regular expression Vertical bar `|` is used to define alternation. W wyrażeniach regularnych pionowa kreska `|` oznacza alternatywę.
Alternation is like a condition between multiple expressions. Now, you may be Działa jak warunek pomiędzy różnymi wyrażeniami. Teraz możesz pomyśleć, że
thinking that character set and alternation works the same way. But the big to działa tak samo jak zestaw znaków. Różnica polega na tym, że zestaw znaków
difference between character set and alternation is that character set works on działa na poziomie znaków, natomiast alternatywa na poziomie wyrażenia. Na przykład
character level but alternation works on expression level. For example, the wyrażenie regularne `(T|t)he|car` oznacza: dużą literę `T` lub małą `t`,
regular expression `(T|t)he|car` means: uppercase character `T` or lowercase następującą po niej literę `h`, następującą po niej literę `e` lub `c`, następującą
`t`, followed by lowercase character `h`, followed by lowercase character `e` or po niej literę `a`, następującą po niej literę `r`.
lowercase character `c`, followed by lowercase character `a`, followed by
lowercase character `r`.
<pre> <pre>
"(T|t)he|car" => <a href="#learn-regex"><strong>The</strong></a> <a href="#learn-regex"><strong>car</strong></a> is parked in <a href="#learn-regex"><strong>the</strong></a> garage. "(T|t)he|car" => <a href="#learn-regex"><strong>The</strong></a> <a href="#learn-regex"><strong>car</strong></a> is parked in <a href="#learn-regex"><strong>the</strong></a> garage.
@ -292,18 +289,17 @@ lowercase character `r`.
[Przetestuj wyrażenie](https://regex101.com/r/fBXyX0/1) [Przetestuj wyrażenie](https://regex101.com/r/fBXyX0/1)
## 2.7 Escaping special character ## 2.7 Znak ucieczki
Backslash `\` is used in regular expression to escape the next character. This Ukośnik `\` w wyrażeniach regularnych jest znakiem ucieczki. Pozwala on
allows us to specify a symbol as a matching character including reserved używać w wyrażeniu zarezerwowanych znaków takich jak `{ } [ ] / \ + * . $ ^ | ?`.
characters `{ } [ ] / \ + * . $ ^ | ?`. To use a special character as a matching Aby użyć znaku specjalnego w wyrażeniu, postaw `\` przed nim.
character prepend `\` before it.
Na przykład wyrażenie `.` dopasowuje każdy znak z wyjątkiem nowej linii.
Żeby dopasować kropkę `.` w wyrażeniu regularnym, trzeba wstawić przed nią ukośnik.
Wyrażenie `(f|c|m)at\.?` oznacza: małe litery `f`, `c` lub `m`, następującą po niej
literę `a`, następującą po niej literę `t`, następującą kropkę `.`, która jest opcjonalna.
For example, the regular expression `.` is used to match any character except
newline. Now to match `.` in an input string the regular expression
`(f|c|m)at\.?` means: lowercase letter `f`, `c` or `m`, followed by lowercase
character `a`, followed by lowercase letter `t`, followed by optional `.`
character.
<pre> <pre>
"(f|c|m)at\.?" => The <a href="#learn-regex"><strong>fat</strong></a> <a href="#learn-regex"><strong>cat</strong></a> sat on the <a href="#learn-regex"><strong>mat.</strong></a> "(f|c|m)at\.?" => The <a href="#learn-regex"><strong>fat</strong></a> <a href="#learn-regex"><strong>cat</strong></a> sat on the <a href="#learn-regex"><strong>mat.</strong></a>
@ -311,24 +307,22 @@ character.
[Przetestuj wyrażenie](https://regex101.com/r/DOc5Nu/1) [Przetestuj wyrażenie](https://regex101.com/r/DOc5Nu/1)
## 2.8 Anchors ## 2.8 Kotwice
In regular expressions, we use anchors to check if the matching symbol is the W wyrażeniach regularnych używamy kotwic aby sprawdzić czy dopasowywany symbol
starting symbol or ending symbol of the input string. Anchors are of two types: jest pierwszym lub ostatnim symbolem w łańcuchu. Są dwa typy: pierwszy to
First type is Caret `^` that check if the matching character is the start kareta `^`, który sprawdza czy znak jest początkiem łańcucha, drugi to dolar `$`,
character of the input and the second type is Dollar `$` that checks if matching który sprawdza czy znak jest ostatnim elementem łańcucha.
character is the last character of the input string.
### 2.8.1 Caret ### 2.8.1 Kareta
Caret `^` symbol is used to check if matching character is the first character Kareta `^` sprawdza czy znak jest początkiem łańcucha. Jeżeli użyjemy takiego
of the input string. If we apply the following regular expression `^a` (if a is wyrażenia `^a` (jeśli a jest pierwszym znakiem) na łańcuchu `abc` to dopasuje
the starting symbol) to input string `abc` it matches `a`. But if we apply nam `a`. Ale jeśli użyjemytakiego wyrażenia `^b` na tym samym łańcuchu, to nie
regular expression `^b` on above input string it does not match anything. zwróci nam nic. Ponieważ w łańcuchu `abc` "b" nie jest pierwszym symbolem.
Because in input string `abc` "b" is not the starting symbol. Let's take a look Spójrzmy teraz na wyrażenie `^(T|t)he` które oznacza: dużą literę `T` lub małą
at another regular expression `^(T|t)he` which means: uppercase character `T` or `t`, która jest początkiem łańcucha, następującą po niej literę `h`, następującą
lowercase character `t` is the start symbol of the input string, followed by po niej literę `e`.
lowercase character `h`, followed by lowercase character `e`.
<pre> <pre>
"(T|t)he" => <a href="#learn-regex"><strong>The</strong></a> car is parked in <a href="#learn-regex"><strong>the</strong></a> garage. "(T|t)he" => <a href="#learn-regex"><strong>The</strong></a> car is parked in <a href="#learn-regex"><strong>the</strong></a> garage.
@ -342,7 +336,7 @@ lowercase character `h`, followed by lowercase character `e`.
[Przetestuj wyrażenie](https://regex101.com/r/jXrKne/1) [Przetestuj wyrażenie](https://regex101.com/r/jXrKne/1)
### 2.8.2 Dollar ### 2.8.2 Dolar
Dollar `$` symbol is used to check if matching character is the last character Dollar `$` symbol is used to check if matching character is the last character
of the input string. For example, regular expression `(at\.)$` means: a of the input string. For example, regular expression `(at\.)$` means: a