Merge branch 'master' into master

This commit is contained in:
Bo 2017-09-05 09:54:53 +08:00 committed by GitHub
commit a75cefc133
8 changed files with 554 additions and 70 deletions

View File

@ -11,6 +11,7 @@
* [中文版](README-cn.md)
* [日本語](README-ja.md)
* [한국어](README-ko.md)
* [Turkish](README-tr.md)
## 什么是正则表达式?
@ -357,10 +358,10 @@
定义一个前置约束(存在)要使用 `()`. 在括号内部使用一个问号和等号: `(?=...)`.
前置约束的内容写在括号中的等号后面.
例如, 表达式 `[T|t]he(?=\sfat)` 匹配 `The``the`, 在括号中我们又定义了前置约束(存在) `(?=\sfat)` ,即 `The``the` 后面紧跟着 `(空格)fat`.
例如, 表达式 `(T|t)he(?=\sfat)` 匹配 `The``the`, 在括号中我们又定义了前置约束(存在) `(?=\sfat)` ,即 `The``the` 后面紧跟着 `(空格)fat`.
<pre>
"[T|t]he(?=\sfat)" => <a href="#learn-regex"><strong>The</strong></a> fat cat sat on the mat.
"(T|t)he(?=\sfat)" => <a href="#learn-regex"><strong>The</strong></a> fat cat sat on the mat.
</pre>
[在线练习](https://regex101.com/r/IDDARt/1)
@ -370,10 +371,10 @@
前置约束-排除 `?!` 用于筛选所有匹配结果, 筛选条件为 其后不跟随着定义的格式
`前置约束-排除` 定义和 `前置约束(存在)` 一样, 区别就是 `=` 替换成 `!` 也就是 `(?!...)`.
表达式 `[T|t]he(?!\sfat)` 匹配 `The``the`, 且其后不跟着 `(空格)fat`.
表达式 `(T|t)he(?!\sfat)` 匹配 `The``the`, 且其后不跟着 `(空格)fat`.
<pre>
"[T|t]he(?!\sfat)" => The fat cat sat on <a href="#learn-regex"><strong>the</strong></a> mat.
"(T|t)he(?!\sfat)" => The fat cat sat on <a href="#learn-regex"><strong>the</strong></a> mat.
</pre>
[在线练习](https://regex101.com/r/V32Npg/1)
@ -381,10 +382,10 @@
### 4.3 `?<= ...` 后置约束-存在
后置约束-存在 记作`(?<=...)` 用于筛选所有匹配结果, 筛选条件为 其前跟随着定义的格式.
例如, 表达式 `(?<=[T|t]he\s)(fat|mat)` 匹配 `fat``mat`, 且其前跟着 `The``the`.
例如, 表达式 `(?<=(T|t)he\s)(fat|mat)` 匹配 `fat``mat`, 且其前跟着 `The``the`.
<pre>
"(?<=[T|t]he\s)(fat|mat)" => The <a href="#learn-regex"><strong>fat</strong></a> cat sat on the <a href="#learn-regex"><strong>mat</strong></a>.
"(?<=(T|t)he\s)(fat|mat)" => The <a href="#learn-regex"><strong>fat</strong></a> cat sat on the <a href="#learn-regex"><strong>mat</strong></a>.
</pre>
[在线练习](https://regex101.com/r/avH165/1)
@ -395,7 +396,7 @@
例如, 表达式 `(?<!(T|t)he\s)(cat)` 匹配 `cat`, 且其前不跟着 `The``the`.
<pre>
"(?&lt;![T|t]he\s)(cat)" => The cat sat on <a href="#learn-regex"><strong>cat</strong></a>.
"(?&lt;!(T|t)he\s)(cat)" => The cat sat on <a href="#learn-regex"><strong>cat</strong></a>.
</pre>
[在线练习](https://regex101.com/r/8Efx5G/1)

View File

@ -11,6 +11,7 @@
* [中文版](README-cn.md)
* [日本語](README-ja.md)
* [한국어](README-ko.md)
* [Turkish](README-tr.md)
## What is Regular Expression?
> Una expresión regular es un grupo de caracteres o símbolos, los cuales son usados para buscar un patrón específico dentro de un texto.

View File

@ -11,14 +11,15 @@
* [中文版](README-cn.md)
* [日本語](README-ja.md)
* [한국어](README-ko.md)
* [Turkish](README-tr.md)
## Qu'est-ce qu'une expression régulière?
> Une expression régulière est un groupement de caractères ou symboles utilisés pour trouver un schéma spécifique dans un texte.
Une expression régulière est un schéma qui est comparée à une chaîne de caractères de gauche à droite. Le mot "Expression régulière"
Une expression régulière est un schéma qui est comparé à une chaîne de caractères (string) de gauche à droite. Le mot "Expression régulière"
est un terme entier, souvent abrégé par "regex" ou "regexp". Une expression régulière est utilisée pour remplacer un texte à l'intérieur
d'une *string* (une chaîne de caractères), valider un formulaire, extraire une portion de string basée sur un schéma, et bien plus encore.
d'une chaîne de caractères (string), valider un formulaire, extraire une portion de chaine de caractères (string) basée sur un schéma, et bien plus encore.
Imaginons que nous écrivons une application et que nous voulons définir des règles pour le choix d'un pseudonyme. Nous voulons autoriser
le pseudonyme à contenir des lettres, des nombres, des underscores et des traits d'union. Nous voulons aussi limiter le nombre
@ -28,8 +29,7 @@ de caractères dans le pseudonyme pour qu'il n'ait pas l'air moche. Nous utiliso
<img src="./img/regexp-fr.png" alt="Expressions régulières">
</p>
L'expression régulière ci-dessus peut accepter les strings `john_doe`, `jo-hn_doe` et `john12_as`. Ça ne fonctionne pas avec `Jo` car
cette string contient une lettre majuscule et elle est trop courte.
L'expression régulière ci-dessus peut accepter les chaines de caractères (string) `john_doe`, `jo-hn_doe` et `john12_as`. Ça ne fonctionne pas avec `Jo` car cette chaine de caractères (string) contient une lettre majuscule et elle est trop courte.
## Table des matières
@ -62,7 +62,7 @@ cette string contient une lettre majuscule et elle est trop courte.
## 1. Introduction
Une expression régulière est un schéma de caractères utilisés pour effectuer une recherche dans un text.
Une expression régulière est un schéma de caractères utilisés pour effectuer une recherche dans un texte.
Par exemple, l'expression régulière `the` signifie : la lettre `t`, suivie de la lettre `h`, suivie de la lettre `e`.
<pre>
@ -81,23 +81,23 @@ L'expression régulière `123` coïncide à la chaîne `123`. Chaque caractère
## 2. Meta-caractères
Les meta-caractères sont les bloques de construction des expressions régulières. Les meta-caractères sont interprétés de manière particulière. Certains meta-caractères ont des significations spéciales et sont écrits entre crochets.
Les meta-caractères sont les blocs de construction des expressions régulières. Les meta-caractères sont interprétés de manière particulière. Certains meta-caractères ont des significations spéciales et sont écrits entre crochets.
Significations des meta-caractères:
|Meta-caractère|Description|
|:----:|----|
|.|Un point coïncide avec n'importe quel caractère unique à part le retour à la ligne.|
|[ ]|Classe de caractères. Coïncide avec n'importe quels caractères entre crochets.|
|[^ ]|Négation de classe de caractère. Coïncide avec n'importe quels caractères qui n'est pas entre les crochets.|
|[ ]|Classe de caractères. Coïncide avec n'importe quel caractère entre crochets.|
|[^ ]|Négation de classe de caractère. Coïncide avec n'importe quel caractère qui n'est pas entre les crochets.|
|*|Coïncide avec 0 ou plus répétitions du caractère précédent.|
|+|Coïncide avec 1 ou plus répétitions du caractère précédent.|
|?|Rend le caractère précédent optionnel.|
|{n,m}|Accolades. Coïncide avec au moins "n" mais pas plus que "m" répétition(s) du caractère précédent.|
|(xyz)|Groupe de caractères. Coïncide avec les caractères "xyz" dans l'ordre exact.|
|&#124;|Alternation (ou). Coïncide soit avec le caractère avant ou après le symbol.|
|&#124;|Alternation (ou). Coïncide soit avec le caractère avant ou après le symbole.|
|&#92;|Échappe le prochain caractère. Cela permet de faire coïncider des caractères réservés tels que <code>[ ] ( ) { } . * + ? ^ $ \ &#124;</code>|
|^|Coïncide avec le début de la chaîne de caractères.|
|$|Coïncide avec la fin de la chaîne de caractères.|
|^|Coïncide avec le début de la chaîne de caractères (string).|
|$|Coïncide avec la fin de la chaîne de caractères (string).|
## 2.1 Full stop
@ -111,7 +111,7 @@ Le full stop `.` est l'exemple le plus simple d'un meta-caratère. Le `.` coïnc
## 2.2 Inclusions de caractères
Les inclusions de caractères sont également appelées classes de caractères. Les crochets sont utilisés pour spécifier les inclusions de caractères. Un trait d'union utilisé dans une inclusion de caractères permet de définir une gamme de caractères. L'ordre utilisé dans la gamme de caractère n'a pas d'importance. Par exemple, l'expression régulière `[Tt]he` signifie : un `T` majuscule ou `t` minuscule, suivi par la lettre `h`, suivie par la lettre `e`.
Les inclusions de caractères sont également appelées classes de caractères. Les crochets sont utilisés pour spécifier les inclusions de caractères. Un trait d'union utilisé dans une inclusion de caractères permet de définir une gamme de caractères. L'ordre utilisé dans la gamme de caractère n'a pas d'importance. Par exemple, l'expression régulière `[Tt]he` signifie : un `T` majuscule ou `t` minuscule, suivie par la lettre `h`, suivie par la lettre `e`.
<pre>
"[Tt]he" => <a href="#learn-regex"><strong>The</strong></a> car parked in <a href="#learn-regex"><strong>the</strong></a> garage.
@ -129,7 +129,7 @@ L'utilisation du point dans une inclusion de caractère signifie toutefois un `.
### 2.2.1 Exclusion de caractères
En règle générale, le caractère circonflexe représente le début d'une chaîne de caractères. Néanmoins, lorsqu'il est utilisé après le crochet ouvrant, il permet d'exclure la gamme de caractère(s). Par exemple, l'expression régulière `[^c]ar` signifie : n'importe quel caractère sauf `c`, suivi par la lettre `a`, suivie par la lettre `r`.
En règle générale, le caractère circonflexe représente le début d'une chaîne de caractères (string). Néanmoins, lorsqu'il est utilisé après le crochet ouvrant, il permet d'exclure la gamme de caractères. Par exemple, l'expression régulière `[^c]ar` signifie : n'importe quel caractère sauf `c`, suivi par la lettre `a`, suivie par la lettre `r`.
<pre>
"[^c]ar" => The car <a href="#learn-regex"><strong>par</strong></a>ked in the <a href="#learn-regex"><strong>gar</strong></a>age.
@ -139,14 +139,13 @@ En règle générale, le caractère circonflexe représente le début d'une cha
## 2.3 Répétitions
Les meta-caractères suivants `+`, `*` ou `?` sont utilisés pour spécifier combien de fois un sous-schéma peut apparaître. Ces meta-caractères agissent
différemment selon la situation dans laquelle ils sont utilisés.
Les meta-caractères suivants `+`, `*` ou `?` sont utilisés pour spécifier combien de fois un sous-schéma peut apparaître. Ces meta-caractères agissent différemment selon la situation dans laquelle ils sont utilisés.
### 2.3.1 Astérisque
Le symbole `*` correspond à zéro ou plus de répétitions du schéma précédent. L'expression régulière `a*` signifie : zéro ou plus de répétitions
du précédent `a` minuscule. Mais si il se trouve après une liste de caractères alors il s'agit de la répétition de la liste entière.
Par exemple, l'expression régulière `[a-z]*` signifie : n'importe combien de lettres minuscules.
Par exemple, l'expression régulière `[a-z]*` signifie : peu importe la chaine tant qu'il s'agit de lettres minuscules.
<pre>
"[a-z]*" => T<a href="#learn-regex"><strong>he</strong></a> <a href="#learn-regex"><strong>car</strong></a> <a href="#learn-regex"><strong>parked</strong></a> <a href="#learn-regex"><strong>in</strong></a> <a href="#learn-regex"><strong>the</strong></a> <a href="#learn-regex"><strong>garage</strong></a> #21.
@ -154,7 +153,7 @@ Par exemple, l'expression régulière `[a-z]*` signifie : n'importe combien de l
[Essayer l'expression régulière](https://regex101.com/r/7m8me5/1)
Le symbole `*` peut être utilisé avec le meta-caractère `.` pour correspondre à n'importe quelle chaîne de caractères `.*`. Le symbole `*` peut être utilisé avec le
Le symbole `*` peut être utilisé avec le meta-caractère `.` pour correspondre à n'importe quelle chaîne de caractères (string) `.*`. Le symbole `*` peut être utilisé avec le
caractère espace vide `\s` pour correspondre à une chaîne d'espaces vides. Par exemple, l'expression `\s*cat\s*` signifie : zéro ou plus
d'espaces, suivis du caractère `c` minuscule, suivi par le caractère `a` minuscule, suivi par le caractère `t` minuscule, suivi par
zéro ou plus d'espaces.
@ -167,7 +166,7 @@ zéro ou plus d'espaces.
### 2.3.2 Le Plus
Le meta-caractère `+` correspond à une ou plusieurs répétitions du caractère précédent. Par exemple, l'expression régulière `c.+t` signifie : la lettre `c` minuscule, suivie par au moins un caractère, suivi par la lettre `t` minuscule. Le `t` coïncide par conséquent avec le dernier `t` de la phrase.
Le meta-caractère `+` correspond à une ou plusieurs répétitions du caractère précédent. Par exemple, l'expression régulière `c.+t` signifie : la lettre `c` minuscule, suivie par au moins un caractère, suivie par la lettre `t` minuscule. Le `t` coïncide par conséquent avec le dernier `t` de la phrase.
<pre>
"c.+t" => The fat <a href="#learn-regex"><strong>cat sat on the mat</strong></a>.
@ -193,7 +192,7 @@ Le meta-caractère `?` rend le caractère précédent optionnel. Ce symbole perm
## 2.4 Accolades
Dans une expression régulière, les accolades, qui sont aussi appelée quantifieurs, sont utilisées pour spécifier le nombre de fois qu'un
Dans une expression régulière, les accolades, qui sont aussi appelées quantifieurs, sont utilisées pour spécifier le nombre de fois qu'un
caractère ou un groupe de caractères peut être répété. Par exemple, l'expression régulière `[0-9]{2,3}` signifie : trouve au moins 2 chiffres mais pas plus de 3
(caractères dans la gamme de 0 à 9).
@ -220,9 +219,9 @@ la virgule l'expression régulière `[0-9]{3}` signifie : trouve exactement 3 ch
## 2.5 Groupement de caractères
Un groupement de caractères est un groupe de sous-schémas qui sont écrits dans des parenthèses `(...)`. Nous avions mentionné plus tôt que, dans une expression régulière,
Un groupement de caractères est un groupe de sous-schémas qui sont écrits entre parenthèses `(...)`. Nous avions mentionné plus tôt que, dans une expression régulière,
si nous mettons un quantifieur après un caractère alors le caractère précédent sera répété. Mais si nous mettons un quantifieur après un groupement de caractères alors
il répète le groupement de caractères entier. Par exemple, l'expression régulière `(ab)*` trouve zéro ou plus de répétitions des caractères "ab".
il répète le groupement de caractères en entier. Par exemple, l'expression régulière `(ab)*` trouve zéro ou plus de répétitions des caractères "ab".
Nous pouvons aussi utiliser le meta-caractère d'alternation `|` à l'intérieur d'un groupement. Par exemple, l'expression régulière `(c|g|p)ar` signifie : caractère `c` minuscule,
`g` ou `p`, suivi par le caractère `a`, suivi par le caractère `r`.
@ -250,7 +249,7 @@ ou le caractère `c` minuscule, suivi par le caractère `a` minuscule, suivit pa
L'antislash `\` est utilisé dans les expressions régulières pour échapper (ignorer) le caractère suivant. Cela permet de spécifier un symbole comme caractère à trouver
y compris les caractères réservés `{ } [ ] / \ + * . $ ^ | ?`. Pour utiliser un caractère spécial comme caractère à trouver, préfixer `\` avant celui-ci.
Par exemple, l'expression régulière `.` est utilisée pour trouver n'importe quel caractère sauf le retour de ligne. Donc pour trouver `.` dans une string
Par exemple, l'expression régulière `.` est utilisée pour trouver n'importe quel caractère sauf le retour de ligne. Donc pour trouver `.` dans une chaine de caractères (string)
l'expression régulière `(f|c|m)at\.?` signifie : la lettre minuscule `f`, `c` ou `m`, suivie par le caractère `a` minuscule, suivi par la lettre
`t` minuscule, suivie par le caractère optionnel `.`.
@ -263,15 +262,15 @@ l'expression régulière `(f|c|m)at\.?` signifie : la lettre minuscule `f`, `c`
## 2.8 Ancres
Dans les expressions régulières, nous utilisons des ancres pour vérifier si le symbole trouvé est le premier ou dernier symbole de la
string. Il y a 2 types d'ancres : Le premier type est le circonflexe `^` qui cherche si le caractère est le premier
caractère de la string et le deuxième type est le Dollar `$` qui vérifie si le caractère est le dernier caractère de la string.
chaine de caractères (string). Il y a 2 types d'ancres : Le premier type est le circonflexe `^` qui cherche si le caractère est le premier
caractère de la chaine de caractères (string) et le deuxième type est le Dollar `$` qui vérifie si le caractère est le dernier caractère de la chaine de caractères (string).
### 2.8.1 Circonflexe
Le symbole circonflexe `^` est utilisé pour vérifier si un caractère est le premier caractère de la string. Si nous appliquons l'expression régulière
suivante `^a` (si a est le premier symbole) à la string `abc`, ça coïncide. Mais si nous appliquons l'expression régulière `^b` sur cette même string,
ça ne coïncide pas. Parce que dans la string `abc` "b" n'est pas le premier symbole. Regardons une autre expression régulière
`^(T|t)he` qui signifie : le caractère `T` majuscule ou le caractère `t` minuscule est le premier symbole de la string,
Le symbole circonflexe `^` est utilisé pour vérifier si un caractère est le premier caractère de la chaine de caractères (string). Si nous appliquons l'expression régulière
suivante `^a` (si a est le premier symbole) à la chaine de caractères (string) `abc`, ça coïncide. Mais si nous appliquons l'expression régulière `^b` sur cette même chaine de caractères (string),
ça ne coïncide pas. Parce que dans la chaine de caractères (string) `abc` "b" n'est pas le premier symbole. Regardons une autre expression régulière
`^(T|t)he` qui signifie : le caractère `T` majuscule ou le caractère `t` minuscule est le premier symbole de la chaine de caractères (string),
suivi par le caractère `h` minuscule, suivi par le caractère `e` minuscule.
<pre>
@ -288,9 +287,9 @@ suivi par le caractère `h` minuscule, suivi par le caractère `e` minuscule.
### 2.8.2 Dollar
Le symbole Dollar `$` est utilisé pour vérifier si un caractère est le dernier caractère d'une string. Par exemple, l'expression régulière
Le symbole Dollar `$` est utilisé pour vérifier si un caractère est le dernier caractère d'une chaine de caractères (string). Par exemple, l'expression régulière
`(at\.)$` signifie : un caractère `a` minuscule, suivi par un caractère `t` minuscule, suivi par un caractère `.` et tout cela doit être
à la fin de la string.
à la fin de la chaine de caractères (string).
<pre>
"(at\.)" => The fat c<a href="#learn-regex"><strong>at.</strong></a> s<a href="#learn-regex"><strong>at.</strong></a> on the m<a href="#learn-regex"><strong>at.</strong></a>
@ -323,7 +322,7 @@ les expressions régulières souvent utilisées. Ces abréviations sont les suiv
La recherche en avant et en arrière sont un type spécifique appelé ***groupe non-capturant*** (utilisés pour trouver un schéma mais pas
pour l'inclure dans la liste de correspondance). Les recherches positives sont utilisées quand nous avons la condition qu'un schéma doit être précédé ou suivi
par un autre schéma. Par exemple, nous voulons tous les chiffres qui sont précédés par le caractère `$` dans la string suivante `$4.44 and $10.88`.
par un autre schéma. Par exemple, nous voulons tous les chiffres qui sont précédés par le caractère `$` dans la chaine de caractères suivante `$4.44 and $10.88`.
Nous allons utiliser l'expression régulière suivante `(?<=\$)[0-9\.]*` qui signifie : trouver tous les nombres qui contiennent le caractère `.` et sont précédés
par le caractère `$`. Les recherches que nous trouvons dans les expressions régulières sont les suivantes:
@ -351,9 +350,9 @@ la recherche en avant positive qui dit quelle est l'expression à chercher. `The
### 4.2 Recherche en avant négative
La recherche en avant négative est utilisée quand nous avons besoin de trouver une string qui n'est pas suivie d'un schéma. La recherche en avant négative
La recherche en avant négative est utilisée quand nous avons besoin de trouver une chaine de caractères (string) qui n'est pas suivie d'un schéma. La recherche en avant négative
est définie de la même manière que la recherche en avant positive mais la seule différence est qu'à la place du signe égal `=` nous utilisons le caractère de négation `!`
i.e. `(?!...)`. Regardons l'expression régulière suivante `[T|t]he(?!\sfat)` qui signifie : trouve tous les mots `The` ou `the` de la string
i.e. `(?!...)`. Regardons l'expression régulière suivante `[T|t]he(?!\sfat)` qui signifie : trouve tous les mots `The` ou `the` de la chaine de caractères (string)
qui ne sont pas suivis du mot `fat` précédé d'un espace.
<pre>
@ -364,8 +363,8 @@ qui ne sont pas suivis du mot `fat` précédé d'un espace.
### 4.3 Recherche en arrière positive
La recherche en arrière positive est utilisée pour trouver une string précédée d'un schéma. La recherche en arrière positive se note
`(?<=...)`. Par exemple, l'expression régulière `(?<=[T|t]he\s)(fat|mat)` signifie : trouve tous les mots `fat` ou `mat` de la string qui
La recherche en arrière positive est utilisée pour trouver une chaine de caractères (string) précédée d'un schéma. La recherche en arrière positive se note
`(?<=...)`. Par exemple, l'expression régulière `(?<=[T|t]he\s)(fat|mat)` signifie : trouve tous les mots `fat` ou `mat` de la chaine de caractères (string) qui
se trouve après le mot `The` ou `the`.
<pre>
@ -376,8 +375,8 @@ se trouve après le mot `The` ou `the`.
### 4.4 Recherche en arrière négative
La recherche en arrière négative est utilisée pour trouver une string qui n'est pas précédée d'un schéma. La recherche en arrière négative se note
`(?<!...)`. Par exemple, l'expression régulière `(?<!(T|t)he\s)(cat)` signifie : trouve tous les mots `cat` de la string qui
La recherche en arrière négative est utilisée pour trouver une chaine de caractères (string) qui n'est pas précédée d'un schéma. La recherche en arrière négative se note
`(?<!...)`. Par exemple, l'expression régulière `(?<!(T|t)he\s)(cat)` signifie : trouve tous les mots `cat` de la chaine de caractères (string) qui
ne se trouvent pas après le mot `The` ou `the`.
<pre>
@ -394,7 +393,7 @@ dans n'importe quel ordre et combinaison et font partie intégrante de la RegExp
|Drapeau|Description|
|:----:|----|
|i|Insensible à la casse : Définit que la correspondance sera insensible à la casse.|
|g|Recherche globale : Recherche la correspondance dans la string entière.|
|g|Recherche globale : Recherche la correspondance dans la chaine de caractères (string) entière.|
|m|Multiligne : Meta-caractère ancre qui agit sur toutes les lignes.|
### 5.1 Insensible à la casse
@ -402,7 +401,7 @@ dans n'importe quel ordre et combinaison et font partie intégrante de la RegExp
Le modifieur `i` est utilisé pour faire une correspondance insensible à la casse. Par exemple, l'expression régulière `/The/gi` signifie : la lettre
`T` majuscule, suivie par le caractère `h` minuscule, suivi par le caractère `e` minuscule. Et à la fin de l'expression régulière, le drapeau `i` dit au
moteur d'expression régulière d'ignorer la casse. Comme vous pouvez le voir, nous mettons aussi un drapeau `g` parce que nous voulons chercher le schéma dans
la string entière.
la chaine de caractères (string) entière.
<pre>
"The" => <a href="#learn-regex"><strong>The</strong></a> fat cat sat on the mat.
@ -418,9 +417,9 @@ la string entière.
### 5.2 Correspondance globale
Le modifieur `g` est utilisé pour faire une recherche globale (trouver toutes les strings plutôt que de s'arrêter à la première correspondance ). Par exemple,
Le modifieur `g` est utilisé pour faire une recherche globale (trouver toutes les chaines de caractères (string) plutôt que de s'arrêter à la première correspondance ). Par exemple,
l'expression régulière `/.(at)/g` signifie : n'importe quel caractère sauf le retour de ligne, suivi par le caractère `a` minuscule, suivi par le caractère
`t` minuscule. Grâce au drapeau `g` à la fin de l'expression régulière maintenant il trouvera toutes les correspondances de toute la string.
`t` minuscule. Grâce au drapeau `g` à la fin de l'expression régulière maintenant il trouvera toutes les correspondances de toute la chaine de caractères (string).
<pre>
"/.(at)/" => The <a href="#learn-regex"><strong>fat</strong></a> cat sat on the mat.
@ -437,9 +436,9 @@ l'expression régulière `/.(at)/g` signifie : n'importe quel caractère sauf le
### 5.3 Multilignes
Le modifieur `m` est utilisé pour trouver une correspondance multiligne. Comme mentionné plus tôt, les ancres `(^, $)` sont utilisés pour vérifier si le schéma
se trouve au début ou à la fin de la string. Mais si nous voulons que l'ancre soit sur chaque ligne nous utilisons le drapeau `m`. Par exemple, l'expression régulière
se trouve au début ou à la fin de la chaine de caractères (string). Mais si nous voulons que l'ancre soit sur chaque ligne nous utilisons le drapeau `m`. Par exemple, l'expression régulière
`/at(.)?$/gm` signifie : le caractère `a` minuscule, suivi par le caractère `t` minuscule, suivi par optionnellement n'importe quel caractère à part le retour de ligne.
Grâce au drapeau `m` maintenant le moteur d'expression régulière trouve le schéma à chaque début de ligne dans la string.
Grâce au drapeau `m` maintenant le moteur d'expression régulière trouve le schéma à chaque début de ligne dans la chaine de caractères (string).
<pre>
"/.at(.)?$/" => The fat

View File

@ -11,6 +11,7 @@
* [中文版](README-cn.md)
* [日本語](README-ja.md)
* [한국어](README-ko.md)
* [Turkish](README-tr.md)
## 正規表現とは
@ -192,6 +193,7 @@
シンボル `+` は直前の文字が 1 個以上続くパターンにマッチします。
例えば `c.+t` という正規表現は小文字の `c` の後に
任意の 1 文字以上が続き、さらに `t` が続くことを意味します。
この `t` は、その文における最後の `t` がマッチします。
<pre>
"c.+t" => The fat <a href="#learn-regex"><strong>cat sat on the mat</strong></a>.
@ -219,6 +221,7 @@
[正規表現の動作確認をする](https://regex101.com/r/kPpO2x/1)
## 2.4 括弧
この`t`は、その文における最後の`t`であることが明確である必要があります。
正規表現における括弧は数量子とも呼ばれますが、文字列がいくつ現れるかを示すために使用されます。
例えば、`[0-9]{2,3}` という正規表現は 2 桁以上 3 桁以下の数字
@ -358,7 +361,7 @@
## 4. 前後参照
しばしば前後参照とも呼ばれる先読みと後読みは **非キャプチャグループ**
先読みと後読み(前後参照とも呼ばれます)は **非キャプチャグループ**
(パターンのマッチングはするがマッチングリストには含まれない)という
特殊な扱いがなされる機能です。
前後参照はあるパターンが別のあるパターンよりも先行または後続して現れることを示すために使用されます。
@ -381,12 +384,12 @@
肯定的な先読みを定義するには括弧を使用します。
その括弧の中で疑問符と等号を合わせて `(?=...)` のようにします。
先読みのパターンは括弧の中の等号の後に記述します。
例えば `[T|t]he(?=\sfat)` という正規表現は小文字の `t` か大文字の `T` のどちらかの後に `h`, `e` が続きます。
例えば `(T|t)he(?=\sfat)` という正規表現は小文字の `t` か大文字の `T` のどちらかの後に `h`, `e` が続きます。
括弧内で肯定的な先読みを定義していますが、これは `The` または `the` の後に
`fat` が続くことを表しています。
<pre>
"[T|t]he(?=\sfat)" => <a href="#learn-regex"><strong>The</strong></a> fat cat sat on the mat.
"(T|t)he(?=\sfat)" => <a href="#learn-regex"><strong>The</strong></a> fat cat sat on the mat.
</pre>
[正規表現の動作確認をする](https://regex101.com/r/IDDARt/1)
@ -396,11 +399,11 @@
否定的な先読みはあるパターンが後続しない全てのマッチング文字列を取得するために使用します。
否定的な先読みは肯定的な先読みと同じように定義しますが、 `=` の代わりに
`!` を使うところが唯一の違いで、`(?!...)` と記述します。
次の正規表現 `[T|t]he(?!\sfat)` について考えてみます。
次の正規表現 `(T|t)he(?!\sfat)` について考えてみます。
これはスペースを挟んで `fat` が後続することがない全ての `The` または `the` を得ることができます。
<pre>
"[T|t]he(?!\sfat)" => The fat cat sat on <a href="#learn-regex"><strong>the</strong></a> mat.
"(T|t)he(?!\sfat)" => The fat cat sat on <a href="#learn-regex"><strong>the</strong></a> mat.
</pre>
[正規表現の動作確認をする](https://regex101.com/r/V32Npg/1)
@ -409,11 +412,11 @@
肯定的な後読みは特定のパターンが先行するような文字列を得るために使用します。
定義の仕方は `(?<=...)` とします。
例えば `(?<=[T|t]he\s)(fat|mat)` という正規表現は
例えば `(?<=(T|t)he\s)(fat|mat)` という正規表現は
`The` または `the` の後に続く全ての `fat` または `mat` が取得できます。
<pre>
"(?<=[T|t]he\s)(fat|mat)" => The <a href="#learn-regex"><strong>fat</strong></a> cat sat on the <a href="#learn-regex"><strong>mat</strong></a>.
"(?<=(T|t)he\s)(fat|mat)" => The <a href="#learn-regex"><strong>fat</strong></a> cat sat on the <a href="#learn-regex"><strong>mat</strong></a>.
</pre>
[正規表現の動作確認をする](https://regex101.com/r/avH165/1)
@ -425,7 +428,7 @@
例えば `(?<!(T|t)he\s)(cat)``The` または `the` に続いていない全ての `cat` が取得できます。
<pre>
"(?&lt;![T|t]he\s)(cat)" => The cat sat on <a href="#learn-regex"><strong>cat</strong></a>.
"(?&lt;!(T|t)he\s)(cat)" => The cat sat on <a href="#learn-regex"><strong>cat</strong></a>.
</pre>
[正規表現の動作確認をする](https://regex101.com/r/8Efx5G/1)
@ -465,8 +468,8 @@
修飾子 `g` はグローバル検索(最初のマッチ列を検索する代わりに全マッチ列を検索する)を
行うために使用します。
例えば `/.(at)/g` という正規表現は、改行を除く任意の文字列の後に
小文字の `a`, `t` が続きます。正規表現の最後にフラグ `g` を渡すことで
入力文字列内の全マッチ列を検索するようにしています。
小文字の `a`, `t` が続きます。正規表現の最後にフラグ `g` を渡すことで
最初のマッチだけではなく(これがデフォルトの動作です)、入力文字列内の全マッチ列を検索するようにしています。
<pre>
"/.(at)/" => The <a href="#learn-regex"><strong>fat</strong></a> cat sat on the mat.

View File

@ -11,6 +11,7 @@
* [中文版](README-cn.md)
* [日本語](README-ja.md)
* [한국어](README-ko.md)
* [Turkish](README-tr.md)
## 정규표현식이란 무엇인가?

478
README-tr.md Normal file
View File

@ -0,0 +1,478 @@
<br/>
<p align="center">
<img src="https://i.imgur.com/bYwl7Vf.png" alt="Learn Regex">
</p><br/>
## Çeviriler:
* [English](README.md)
* [Español](README-es.md)
* [Français](README-fr.md)
* [中文版](README-cn.md)
* [日本語](README-ja.md)
* [한국어](README-ko.md)
* [Turkish](README-tr.md)
## Düzenli İfade Nedir?
> Düzenli ifade, bir metinden belirli bir deseni bulmak için kullanılan bir karakter veya sembol grubudur.
Bir düzenli ifade soldan sağa söz konusu harf öbekleriyle eşleşen bir desendir. "Regular expression" söylemesi zor bir tabirdir, genellikle "regex" ya da "regexp" olarak kısaltılmış terimler olarak bulacaksınız. Düzenli ifade bir harf öbeğinde ki bir metin değiştirmek, form doğrulamak, bir desen eşleşmesine dayalı harf öbeğinden bir alt harf öbeği ayıklamak ve çok daha fazlası için kullanılır.
Bir uygulama yazdığınızı hayal edin ve bir kullanıcı kullanıcı adını seçtiğinde kullanıcı adı için kurallar belirlemek istiyorsunuz. Kullanıcı adının harfler, sayılar, altçizgiler ve tireler içermesine izin vermek istiyoruz. Ayrıca, Kullanıcı adındaki karakter sayısını sınırlamak istiyoruz böylece çirkin görünmeyecek. Bir kullanıcı adını doğrulamak için aşağıdaki düzenli ifadeyi kullanıyoruz:
<br/><br/>
<p align="center">
<img src="./img/regexp-tr.png" alt="Regular expression">
</p>
Yukardaki düzenli ifade `john_doe`, `jo-hn_doe` ve `john12_as` gibi girişleri kabul edebilir.
`Jo` girişi uyuşmaz, çünkü harf öbeği büyük harf içeriyor ve aynı zamanda uzunluğu 3 karakterden az.
## İçindekiler
- [Temel Eşleştiriciler](#1-temel-eşleştiriciler)
- [Meta Karakterler](#2-meta-karakterler)
- [Nokta](#21-nokta)
- [Karakter takımı](#22-karakter-takımı)
- [Negatiflenmiş karakter seti](#221-negatiflenmiş-karakter-seti)
- [Tekrarlar](#23-tekrarlar)
- [Yıldız İşareti](#231-yıldız-İşareti)
- [Artı İşareti](#232-artı-İşareti)
- [Soru İşareti](#233-soru-İşareti)
- [Süslü Parantez](#24-süslü-parantez)
- [Karakter Grubu](#25-karakter-grubu)
- [Değişim](#26-değişim)
- [Özel Karakter Hariç Tutma](#27-Özel-karakter-hariç-tutma)
- [Sabitleyiciler](#28-sabitleyiciler)
- [Ters v işareti](#281-Şapka-İşareti)
- [Dolar işareti](#282-dolar-İşareti)
- [Kısaltma Karakter Takımları](#3-kısaltma-karakter-takımları)
- [Bakınmak](#4-bakınmak)
- [Olumlu Bakınma](#41-positive-lookahead)
- [Olumsuz Bakınma](#42-negative-lookahead)
- [Positive Lookbehind](#43-positive-lookbehind)
- [Negative Lookbehind](#44-negative-lookbehind)
- [İşaretler](#5-İşaretler)
- [Büyük/Küçük harf duyarlılığı](#51-büyükküçük-harf-duyarlılığı)
- [Bütünsel Arama](#52-genel-arama)
- [Çok satırlı](#53-Çok-satırlı)
## 1. Temel Eşleştiriciler
Bir düzenli ifade bir metin içinde arama yapabilmek için kullandığımız bir karakter desenidir.
Örneğin, `the` düzenli ifadesi şu anlama gelir: `t` harfi ardından `h`, ardından `e` harfi gelir.
<pre>
"the" => The fat cat sat on <a href="#learn-regex"><strong>the</strong></a> mat.
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/dmRygT/1)
`123` düzenli ifadesi `123` harf öbeğiyle eşleşir. Düzenli ifade birbiri ardına, girilen harf öbeğindeki her karakter düzenli ifadenin içindeki her karakterle karşılaştırılarak eşleştirilir. Düzenli ifadeler normal olarak büyük/küçük harfe duyarlıdırlar, yani `The` düzenli ifadesi `the` harf öbeğiyle eşleşmez.
<pre>
"The" => <a href="#learn-regex"><strong>The</strong></a> fat cat sat on the mat.
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/1paXsy/1)
## 2. Meta Karakterler
Meta karakterler düzenli ifadelerin yapı taşlarıdırlar. Meta karakterler kendileri için değil bunun yerine bazı özel yollarla yorumlanırlar. Bazı meta karakterler özel anlamları vardır ve bunlar köşeli parantez içinde yazılırlar.
Meta karakterler aşağıdaki gibidir:
|Meta karakter|Açıklama|
|:----:|----|
|.|Satır sonuc hariç herhangi bir karakterle eşleşir.|
|[ ]|Köşeli parantezler arasında bulunan herhangi bir karakterle eşleşir.|
|[^ ]|Köşeli parantez içerisinde yer alan `^` işaretinden sonra girilen karakterler haricindeki karakterlerle eşleşir.|
|*|Kendisinden önce yazılan karakterin sıfır veya daha fazla tekrarı ile eşleşir.|
|+|Kendisinden önce yazılan karakterin bir veya daha fazla tekrarı ile eşleşir.|
|?|Kendisinden önce yazılan karakterin varlık durumunu opsiyonel kılar.|
|{n,m}|Kendisinden önce yazılan karakterin en az `n` en fazla `m` değeri kadar olmasını ifade eder.|
|(xyz)|Verilen sırayla `xyz` karakterleriyle eşleşir.|
|&#124;|`|` karakterinden önce veya sonra verilen ifadelerin herhangi biriyle eşleşir. Or anlamı verir.|
|&#92;|Sonraki karakteri kaçırır. Bu, ayrılmış karakterleri eşleştirmenizi sağlar <code>[ ] ( ) { } . * + ? ^ $ \ &#124;</code>|
|^|Girilen verinin başlangıcını ifade eder.|
|$|Girilen veririnin sonunu ifade eder.|
## 2.1 Nokta
Nokta `.` meta karakterin en basit örneğidir. `.` meta karakteri satır başlangıcı hariç herhangi bir karakterle eşleşir.
Örneğin, `.ar` düzenli ifadesinin anlamı: herhangi bir karakterin ardından `a` harfi ve `r` harfi gelir.
<pre>
".ar" => The <a href="#learn-regex"><strong>car</strong></a> <a href="#learn-regex"><strong>par</strong></a>ked in the <a href="#learn-regex"><strong>gar</strong></a>age.
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/xc9GkU/1)
## 2.2 Karakter Takımı
Karakter takımları aryıca Karakter sınıfı olarak bilinir. Karakter takımlarını belirtmek için köşeli ayraçlar kullanılır.
Karakterin aralığını belirtmek için bir karakter takımında tire kullanın. Köşeli parantezlerdeki karakter aralığının sıralaması önemli değildir.
Örneğin, `[Tt]he` düzenli ifadesinin anlamı: bir büyük `T` veya küçük `t` harflerinin ardından sırasıyla `h` ve `e` harfi gelir.
<pre>
"[Tt]he" => <a href="#learn-regex"><strong>The</strong></a> car parked in <a href="#learn-regex"><strong>the</strong></a> garage.
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/2ITLQ4/1)
Bununla birlikte, bir karakter takımı içerisindeki bir periyot bir tam periyot demektir.
`ar[.]` düzenli ifadesinin anlamı: Küçük `a` karakteri ardından `r` harfi gelir, ardından bir `.` karakteri gelir.
<pre>
"ar[.]" => A garage is a good place to park a c<a href="#learn-regex"><strong>ar.</strong></a>
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/wL3xtE/1)
### 2.2.1 Negatiflenmiş karakter seti
Genellikle, şapka `^` sembolü harf öbeğinin başlangıcını temsil eder, ama köşeli parantez içinde kullanıldığında verilen karakter takımını hariç tutar.
Örneğin, `[^c]ar` ifadesinin anlamı: `c` harfinden hariç herhangi bir harfin ardından `a`, ardından `r` gelir.
<pre>
"[^c]ar" => The car <a href="#learn-regex"><strong>par</strong></a>ked in the <a href="#learn-regex"><strong>gar</strong></a>age.
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/nNNlq3/1)
## 2.3 Tekrarlar
`+`, `*` ya da `?` meta karakterlerinden sonra bir alt desenin kaç defa tekrar edebileceğini belirtmek için kullanılır. Bu meta karakterler farklı durumlarda farklı davranırlar.
### 2.3.1 Yıldız İşareti
`*` sembolü, kendinden önce girilen eşlemenin sıfır veya daha fazla tekrarıyla eşleşir. Ama bir karakter seti ya da sınıf sonrasına girildiğinde, tüm karakter setinin tekrarlarını bulur.
`a*` düzenli ifadesinin anlamı: `a` karakterinin sıfır veya daha fazla tekrarı.
`[a-z]*` düzenli ifadesinin anlamı: bir satırdaki herhangi bir sayıdaki küçük harfler.
<pre>
"[a-z]*" => T<a href="#learn-regex"><strong>he</strong></a> <a href="#learn-regex"><strong>car</strong></a> <a href="#learn-regex"><strong>parked</strong></a> <a href="#learn-regex"><strong>in</strong></a> <a href="#learn-regex"><strong>the</strong></a> <a href="#learn-regex"><strong>garage</strong></a> #21.
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/7m8me5/1)
`*` sembolü `.` meta karakteri ile `.*` karakterinin herhangi harf öbeğine eşleştirmek için kullanılabilir. `*` sembolü boşluk karakteriyle `\s` bir harf öbeğinde boşluk karakterlerini eşleştirmek için kullanılabilir.
Örneğin, `\s*cat\s*` düzenli ifadesinin anlamı: sıfır veya daha fazla boşluk ardından küçük `c` karakteri gelir, ardından küçük `a` karakteri gelir, ardından küçük `t` karakteri gelir, ardından sıfır veya daha fazla boşluk gelir.
<pre>
"\s*cat\s*" => The fat<a href="#learn-regex"><strong> cat </strong></a>sat on the <a href="#learn-regex">con<strong>cat</strong>enation</a>.
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/gGrwuz/1)
### 2.3.2 Artı İşareti
`+` sembolü, kendinden önce girilen eşlemenin bir veya daha fazla tekrarıyla eşleşir.
Örneğin, `c.+t` ifadesinin anlamı: küçük `c` harfi, ardından en az bir karakter gelir, ardından küçük `t` karakteri gelir.
Örnekte açıklamak gereken önemli nokta: `t` harfi cümledeki son `t` harfi olacaktır. `c` ve `t` harfi arasında en az bir karakter vardır.
<pre>
"c.+t" => The fat <a href="#learn-regex"><strong>cat sat on the mat</strong></a>.
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/Dzf9Aa/1)
### 2.3.3 Soru İşareti
Düzenli ifadelerde `?` meta karakterinden önce girilen karakteri opsiyonel olarak tanımlar. Bu sembol önce gelen karakterin sıfır veya bir örbeğiyle eşleşir.
Örneğin, `[T]?he` ifadesinin anlamı: opsiyonel büyük `T` harfi, ardından küçük `h` karakteri gelir, ardından küçük `e` karakteri gelir.
<pre>
"[T]he" => <a href="#learn-regex"><strong>The</strong></a> car is parked in the garage.
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/cIg9zm/1)
<pre>
"[T]?he" => <a href="#learn-regex"><strong>The</strong></a> car is parked in t<a href="#learn-regex"><strong>he</strong></a> garage.
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/kPpO2x/1)
## 2.4 Süslü Parantez
Düzenli ifadelerde miktar belirliyiciler olarakda bilinen süslü parantezler, bir karakterin veya karakter grubunun kaç defa tekrar edebileceğini belirtmek için kullanılırlar.
Örneğin, `[0-9]{2,3}` ifadesinin anlamı: 0 ile 0 aralığındaki karakterlerden, en az 2 en fazla 3 defa ile eşleş.
<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.
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/juM86s/1)
İkinci numarayı boş bırakabiliriz.
Örneğin, `[0-9]{2,}` ifadesinin anlamı: En az 2 veya daha fazla defa eşleş.
Düzenli ifadeden virgülü kaldırırsak `[0-9]{3}`: doğrudan 3 defa eşleşir.
<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.
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/Gdy4w5/1)
<pre>
"[0-9]{3}" => The number was 9.<a href="#learn-regex"><strong>999</strong></a>7 but we rounded it off to 10.0.
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/Sivu30/1)
## 2.5 Karakter Grubu
Karakter grubu parantezler içine yazılmış alt desenler grubudur. Daha önce tasarım deseninde değindiğimiz gibi, bir karakterden önce bir miktar belirleyici koyarsak önceki karakteri tekrar eder. Fakat miktar belirleyiciyi bir karakter grubundan sonra koyarsak tüm karakter grubunu tekrarlar.
Örneğin: `(ab)*` düzenli ifadesi "ab" karakterinin sıfır veya daha fazla tekrarıyla eşleşir.
Ayrıca karakter grubu içinde `|` meta karakterini kullanabiliriz.
Örneğin, `(c|g|p)ar` düzenli ifadesinin anlamı: küçük `c`, `g` veya `p` karakteri, ardından `a` karakteri, ardından `r` karakteri gelir.
<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.
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/tUxrBG/1)
## 2.6 Değişim
Düzenli ifadede dik çizgi alternasyon(değişim, dönüşüm) tanımlamak için kullanılır. Alternasyon birden fazla ifade arasındaki bir koşul gibidir. Şu an, karakter grubu ve alternasyonun aynı şekilde çalıştığını düşünüyor olabilirsiniz. Ama, Karakter grubu ve alternasyon arasındaki büyük fark karakter grubu karakter düzeyinde çalışır ama alternasyon ifade düzeyinde çalışır.
Örneğin, `(T|t)he|car` düzenli ifadesinin anlamı: Büyük `T` ya da küçük `t` karakteri, ardından küçük `h` karakteri, ardından küçük `e` ya da `c` karakteri, ardından küçük `a`, ardından küçük `r` karakteri gelir.
<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.
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/fBXyX0/1)
## 2.7 Özel Karakter Hariç Tutma
`\` işareti sonraki karakteri hariç tutmak için kullanılır. Bu bir semboülü ayrılmış karakterlerde `{ } [ ] / \ + * . $ ^ | ?` dahil olmak üzere eşleşen bir karakter olarak belirtmemizi sağlar. Bir özel karakteri eşleşen bir karakter olarak kullanmak için önüne `\` işareti getirin.
Örneğin, `.` düzenli ifadesi yeni satır hariç herhangi bir karakteri eşleştirmek için kullanılır.
Bir harf öbeği içinde nokta `.` karakterini yakalamak için `.` ayrılmış karakterini hariç tutmamız gerekir. Bunun için nokta önüne `\` işaretini koymamız gereklidir.
`(f|c|m)at\.?` düzenli ifadesinin anlamı: küçük `f`, `c`ya da `m` harfi, ardından küçük `a` harfi, ardından küçük `t` harfi, ardından opsiyonel `.` karakteri gelir.
<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>
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/DOc5Nu/1)
## 2.8 Sabitleyiciler
Düzenli ifadelerde, eşleşen sembolün girilen harf öbeğinin başlangıç sembolü veya bitiş sembolü olup olmadığını kontrol etmek için sabitleyicileri kullanırız.
Sabitleyiciler iki çeşittir: İlk çeşit eşleşen karakterin girişin ilk karakteri olup olmadığını kontrol eden şapka `^` karakteri, ve ikinci çeşit eşleşen karakterin girişin son karakteri olup olmadığını kontrol eden dolar `$` karakteridir.
### 2.8.1 Şapka İşareti
Şapka `^` işareti eşleşen karakterin giriş harf öbeğinin ilk karakteri olup olmadığını kontrol etmek için kullanılır.
Eğer `^a` düzenli ifadesini `abc` harf öbeğine uygularsak `a` ile eşleşir. Ama `^b` ifadesini uygularsak bir eşleşme bulamayız. Bunun nedeni `abc` harf öbeğinde `b` karakterinin başlangıç karakteri olmamasıdır.
Bir başka örnek üzerinden ilerlersek,
`^(T|t)he` düzenli ifadesinin anlamı: büyük `T` ya da `t` karakteri giriş harf öbeğinin ilk karakteri olmak üzere, ardından küçük `h`, ardından küçük `e` karakteri gelir.
<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.
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/5ljjgB/1)
<pre>
"^(T|t)he" => <a href="#learn-regex"><strong>The</strong></a> car is parked in the garage.
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/jXrKne/1)
### 2.8.2 Dolar İşareti
Dolar `$` işareti eşleşen karakterin giriş harf öbeğinin son karakteri olup olmadığını kontrol etmek için kullanılır.
Örneğin, `(at\.)$` ifadesinin anlamı: küçük bir `a` karakteri, ardından küçük bir `t` karakteri, ardıdan nokta `.` karakteri gelir ve bu eşleşme harf öbeğinin sonunda olmalıdır.
<pre>
"(at\.)" => The fat c<a href="#learn-regex"><strong>at.</strong></a> s<a href="#learn-regex"><strong>at.</strong></a> on the m<a href="#learn-regex"><strong>at.</strong></a>
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/y4Au4D/1)
<pre>
"(at\.)$" => The fat cat. sat. on the m<a href="#learn-regex"><strong>at.</strong></a>
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/t0AkOd/1)
## 3. Kısaltma Karakter Takımları
Regex, yaygın olarak kullanılan düzenli ifadeler için uygun kısaltmalar sunan sık kullanılan karakter setleri için kısaltmalar sağlar.
Kullanılan karakter setleri kısaltmaları aşağıdaki gibidir:
|Kısaltma|Açıklama|
|:----:|----|
|.|Satır başı hariç herhangi bir karakter|
|\w|Alfanumerik karakterlerle eşleşir: `[a-zA-Z0-9_]`|
|\W|Alfanumerik olmayan karakterlerle eşleşir: `[^\w]`|
|\d|Rakamlarla eşlelir: `[0-9]`|
|\D|Rakam olmayan karakterlerle eşleşir: `[^\d]`|
|\s|Boşluk karakteri ile eşleşir: `[\t\n\f\r\p{Z}]`|
|\S|Boşluk karakteri olmayan karakterlerle eşleşir: `[^\s]`|
## 4. Bakınmak
Bakınma sembolleri, bir ifade öncesinde veya sonrasında başka bir ifademiz olduğunda kullanılırlar.
Örneğin, `$4.44 ve $10.88` girişlerinden `$` karakteri önündeki tüm sayıları almak istiyoruz, bu durumda `(?<=\$)[0-9\.]*` ifadesini kullanırız.
`(?<=\$)[0-9\.]*` ifadesinin anlamı: `.` karakterini içeren ve `$` karakteriyle devam eden tüm sayıları al.
Düzenli ifadelerde kullanılan bakınma sembolleri aşağıdadır:
|Sembol|Açıklama|
|:----:|----|
|?=|Positive Lookahead (Verdiğimiz ifade sonrası arar ve `eşleşme varsa` sonuç döndürür.)|
|?!|Negative Lookahead (Verdiğimiz ifade sonrası arar ve `eşleşme yoksa` sonuç döndürür.)|
|?<=|Positive Lookbehind (Verdiğimiz ifade öncesini arar ve `eşleşme varsa` sonuç döndürür.)|
|?<-!-|Negative Lookbehind Verdiğimiz ifade öncesini arar ve `eşleşme yoksa` sonuç döndürür.|
### 4.1 Positive Lookahead
Positive Lookahead, ifadenin ilk bölümü bakınma ifadesiyle devam etmesi gerektiğini savunur. Bulunan eşleşme yalnızca ifadenin ilk bölümüyle eşleşen metin içerir. Olumlu bir bakınma tanımlamak için, içinde eşittir işareti yer alan parantezler `(?=...)` şeklinde kullanılır. Bakınma ifadesi parantezler içinde eşittir işaretinden sonra yazılır.
Örneğin, `[T|t]he(?=\sfat)` ifadesinin anlamı: opsiyonel küçük bir `t` ya da büyük `T` harfi, ardından `h` harfi gelir, ardından `e` harfi gelir. Parantez içinde ise bu dizilimin bir boşluk karakterinden sonra `fat` öbeğiyle devam edeceğini tanımlıyoruz.
<pre>
"[T|t]he(?=\sfat)" => <a href="#learn-regex"><strong>The</strong></a> fat cat sat on the mat.
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/IDDARt/1)
### 4.2 Negative Lookahead
Negative Lookahead sembolü positive lookahead tersine, verdiğimiz desenle devam etmemesi durumunda eşleşir. Bu sembol positive lookahead gibi tanımlanır ama `=` işareti yerine `!` kullanılır.
`[T|t]he(?!\sfat)` ifadesinin anlamı: opsiyonel küçük bir `t` ya da büyük `T` harfi, ardından `h` harfi gelir, ardından `e` harfi gelir, ardından öncesinde boşluk olan bir `fat` öbeği olmamalıdır.
<pre>
"[T|t]he(?!\sfat)" => The fat cat sat on <a href="#learn-regex"><strong>the</strong></a> mat.
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/V32Npg/1)
### 4.3 Positive Lookbehind
Positive Lookbehind, belirli bir desenden önceki eşleşmeleri almak için kullanılır. `(?<=...)` ile gösterilir.
Örneğin, `(?<=[T|t]he\s)(fat|mat)` ifadesinin anlamı: Öncesinde `The` veya `the` öbekleri olan tüm `fat` veya `mat` öbeklerini getir.
<pre>
"(?<=[T|t]he\s)(fat|mat)" => The <a href="#learn-regex"><strong>fat</strong></a> cat sat on the <a href="#learn-regex"><strong>mat</strong></a>.
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/avH165/1)
### 4.4 Negative Lookbehind
Negative Lookbehind, belirli bir desenden önce olmayan eşleşmeleri almak için kullanılır. `(?<=!..)` ile gösterilir.
Örneğin, `(?<!(T|t)he\s)(cat)` ifadesinin anlamı: Öncesinde `The` veya `the` öbekleri yer almayan tüm `cat` öbeklerini getir.
<pre>
"(?&lt;![T|t]he\s)(cat)" => The cat sat on <a href="#learn-regex"><strong>cat</strong></a>.
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/8Efx5G/1)
## 5. İşaretler
İşaretler ayrıca düzenleyiciler olarak bilinirler, çünkü onlar bir düzenli ifadenin çıktısını düzenlerler. Bu işaretler herhangi bir sırada veya kombinasyonda kullanılabilirler, ve bunlar Düzenli İfadelerin ayrılmaz bir parçasıdırlar.
|İşaret|Açıklama|
|:----:|----|
|i|Büyük küçük harf duyarlılık: Eşleştirmeleri küçük/büyük harfe karşı duyarsız yapar.|
|g|Genel Arama: Girilen harf öbeği boyunca bir desen arar.|
|m|Çok satırlı: Sabitleyici meta karakteri her satırda çalışır.|
### 5.1 Büyük/Küçük harf duyarlılığı
`ì` işaretleyicisi büyük/küçük harfe duyarsız eşleştirme yapmak için kullanılır.
Örneğin, `/The/gi` ifadesi: büyük `T` harfi, ardından küçük `h` harfi, ardından küçük `e` harfi gelir. ifadenin sonunda yer alan `i` işareti büyük-küçük harfe karşı duyarsız olması gerektiğini belirtir. Ayrıca `g` işaretinide kullandığımızı görebilirsiniz, tüm text içinde bu aramayı yapmak istediğimiz için `g` işaretini ayrıca belirtiyoruz.
<pre>
"The" => <a href="#learn-regex"><strong>The</strong></a> fat cat sat on the mat.
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/dpQyf9/1)
<pre>
"/The/gi" => <a href="#learn-regex"><strong>The</strong></a> fat cat sat on <a href="#learn-regex"><strong>the</strong></a> mat.
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/ahfiuh/1)
### 5.2 Genel Arama
`g` işareti bir giriş içinde eşleşen tüm varsayonları bulmak için kullanılır. `g` işareti kullanılmazsa ilk eşleşme bulunduktan sonra arama sona erer.
<pre>
"/.(at)/" => The <a href="#learn-regex"><strong>fat</strong></a> cat sat on the mat.
</pre>
[Test the regular expression](https://regex101.com/r/jnk6gM/1)
<pre>
"/.(at)/g" => The <a href="#learn-regex"><strong>fat</strong></a> <a href="#learn-regex"><strong>cat</strong></a> <a href="#learn-regex"><strong>sat</strong></a> on the <a href="#learn-regex"><strong>mat</strong></a>.
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/dO1nef/1)
### 5.3 Çok Satırlı
`m` işareti çok satırlı bir eşleşme sağlamak için kullanılır. Daha önce sabitleyicilerde gördüğümüz gibi `(^, $)` sembolleri aradığımız desenin harf öbeğinin başında veya sonunda olup olmadığını kontrol etmemiz için kullanılır. Bu sabitleyicilerin tüm satırlarda çalışması için `m` işaretini kullanırız.
Örneğin, `/at(.)?$/gm` ifadesinin anlamı: küçük `a` harfi, ardından küçük `t` harfi gelir, ardından opsiyonel olarak yeni satır hariç herhangi birşey gelebilir. `m` işaretini kullandığımız için bir girişin her satırının sonunda eşleştirir.
<pre>
"/.at(.)?$/" => The fat
cat sat
on the <a href="#learn-regex"><strong>mat.</strong></a>
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/hoGMkP/1)
<pre>
"/.at(.)?$/gm" => The <a href="#learn-regex"><strong>fat</strong></a>
cat <a href="#learn-regex"><strong>sat</strong></a>
on the <a href="#learn-regex"><strong>mat.</strong></a>
</pre>
[Düzenli ifadeyi test edin](https://regex101.com/r/E88WE2/1)
## Contribution
* Report issues
* Open pull request with improvements
* Spread the word
* Reach out to me directly at ziishaned@gmail.com or [![Twitter URL](https://img.shields.io/twitter/url/https/twitter.com/ziishaned.svg?style=social&label=Follow%20%40ziishaned)](https://twitter.com/ziishaned)
## License
MIT © [Zeeshan Ahmed](mailto:ziishaned@gmail.com)

View File

@ -12,6 +12,7 @@
* [中文版](README-cn.md)
* [日本語](README-ja.md)
* [한국어](README-ko.md)
* [Turkish](README-tr.md)
## What is Regular Expression?
@ -380,8 +381,8 @@ shorthand character sets are as follows:
## 4. Lookaround
Lookbehind and lookahead sometimes known as lookaround are specific type of
***non-capturing group*** (Use to match the pattern but not included in matching
Lookbehind and lookahead (also called lookaround) are specific types of
***non-capturing groups*** (Used 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 pattern. For example, we want to get all
numbers that are preceded by `$` character from the following input string
@ -405,13 +406,13 @@ that is matched by the first part of the expression. To define a positive
lookahead, parentheses are used. Within those parentheses, a question mark with
equal sign is used like this: `(?=...)`. Lookahead expression is written after
the equal sign inside parentheses. For example, the regular expression
`[T|t]he(?=\sfat)` means: optionally match lowercase letter `t` or uppercase
`(T|t)he(?=\sfat)` means: optionally match lowercase letter `t` or uppercase
letter `T`, followed by letter `h`, followed by letter `e`. In parentheses we
define positive lookahead which tells regular expression engine to match `The`
or `the` which are followed by the word `fat`.
<pre>
"[T|t]he(?=\sfat)" => <a href="#learn-regex"><strong>The</strong></a> fat cat sat on the mat.
"(T|t)he(?=\sfat)" => <a href="#learn-regex"><strong>The</strong></a> fat cat sat on the mat.
</pre>
[Test the regular expression](https://regex101.com/r/IDDARt/1)
@ -422,12 +423,12 @@ 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 i.e. `(?!...)`. Let's take a look at the following
regular expression `[T|t]he(?!\sfat)` which means: get all `The` or `the` words
regular expression `(T|t)he(?!\sfat)` which means: get all `The` or `the` words
from input string that are not followed by the word `fat` precedes by a space
character.
<pre>
"[T|t]he(?!\sfat)" => The fat cat sat on <a href="#learn-regex"><strong>the</strong></a> mat.
"(T|t)he(?!\sfat)" => The fat cat sat on <a href="#learn-regex"><strong>the</strong></a> mat.
</pre>
[Test the regular expression](https://regex101.com/r/V32Npg/1)
@ -436,11 +437,11 @@ character.
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
regular expression `(?<=(T|t)he\s)(fat|mat)` means: get all `fat` or `mat` words
from input string that are after the word `The` or `the`.
<pre>
"(?<=[T|t]he\s)(fat|mat)" => The <a href="#learn-regex"><strong>fat</strong></a> cat sat on the <a href="#learn-regex"><strong>mat</strong></a>.
"(?<=(T|t)he\s)(fat|mat)" => The <a href="#learn-regex"><strong>fat</strong></a> cat sat on the <a href="#learn-regex"><strong>mat</strong></a>.
</pre>
[Test the regular expression](https://regex101.com/r/avH165/1)
@ -453,7 +454,7 @@ regular expression `(?<!(T|t)he\s)(cat)` means: get all `cat` words from input
string that are not after the word `The` or `the`.
<pre>
"(?&lt;![T|t]he\s)(cat)" => The cat sat on <a href="#learn-regex"><strong>cat</strong></a>.
"(?&lt;!(T|t)he\s)(cat)" => The cat sat on <a href="#learn-regex"><strong>cat</strong></a>.
</pre>
[Test the regular expression](https://regex101.com/r/8Efx5G/1)
@ -497,7 +498,7 @@ 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 character `t`. Because we provided `g` flag at the end of
the regular expression now it will find every matches from whole input string.
the regular expression now it will find all matches in the input string, not just the first one (which is the default behavior).
<pre>
"/.(at)/" => The <a href="#learn-regex"><strong>fat</strong></a> cat sat on the mat.

BIN
img/regexp-tr.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB