You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Regular expressions are patterns that provide a powerful way to search and replace in text.
3
+
Düzenli ifadeler, metinde arama ve değiştirme yapmak için etkili bir yöntem sağlayan kalıplardır.
4
4
5
-
In JavaScript, they are available via the [RegExp](mdn:js/RegExp)object, as well as being integrated in methods of strings.
5
+
JavaScript'te, [RegExp](mdn:js/RegExp)nesnesi aracılığıyla kullanılabilirler ve ayrıca string metotlarına entegre edilmişlerdir.
6
6
7
-
## Regular Expressions
7
+
## Düzenli İfadeler
8
8
9
-
A regular expression (also "regexp", or just "reg") consists of a *pattern* and optional *flags*.
9
+
Bir düzenli ifade ("regexp" veya sadece "reg") bir _kalıp_ ve isteğe bağlı *işaretler*den oluşur.
10
10
11
-
There are two syntaxes that can be used to create a regular expression object.
11
+
Düzenli ifade nesnesi oluşturmak için kullanılabilecek iki sözdizimi vardır.
12
12
13
-
The "long" syntax:
13
+
Uzun olan sözdizimi:
14
14
15
15
```js
16
-
regexp =newRegExp("pattern", "flags");
16
+
regexp =newRegExp("kalıp", "işaretler");
17
17
```
18
18
19
-
And the "short" one, using slashes `"/"`:
19
+
Ve bölme işareti "/" kullanan kısa olanı:
20
20
21
21
```js
22
-
regexp =/pattern/; //no flags
23
-
regexp =/pattern/gmi; //with flags g,m and i (to be covered soon)
22
+
regexp =/kalıp/; //işaret yok
23
+
regexp =/kalıp/gim; //g, m ve i işaretleriyle birlikte (yakında ele alınacak)
24
24
```
25
25
26
-
Slashes `pattern:/.../`tell JavaScript that we are creating a regular expression. They play the same role as quotes for strings.
26
+
Bölme işaretleri `pattern:/.../` JavaScript'e düzenli bir ifade oluşturduğumuzu söyler. Aynı tırnak işaretlerinin String oluşturduğumuzu söylediği gibi.
27
27
28
-
In both cases `regexp` becomes an instance of the built-in `RegExp` class.
28
+
Her iki durumda da `regexp`, `RegExp` sınıfının bir örneği oluşturulmuş olur.
29
29
30
-
The main difference between these two syntaxes is that pattern using slashes `/.../`does not allow for expressions to be inserted (like string template literals with `${...}`). They are fully static.
30
+
Bu ikisi arasındaki temel fark, bölme işareti `/.../`kullanan modelin kalıba expression eklenmesine izin vermemesidir (`${...}` kullanan string şablonları gibi). Tamamen statiktirler.
31
31
32
-
Slashes are used when we know the regular expression at the code writing time -- and that's the most common situation. While `new RegExp`, is more often used when we need to create a regexp "on the fly" from a dynamically generated string. For instance:
32
+
Bölme işaretleri, kod yazarken düzenli ifadeyi önceden bildiğimizde kullanılır -- ve bu en yaygın durumdur. `new RegExp` ise, dinamik olarak oluşturulan bir string'den anında bir regexp oluşturmamız gerektiğinde daha sık kullanılır. Örneğin:
33
33
34
34
```js
35
-
let tag =prompt("What tag do you want to find?", "h2");
35
+
let tag =prompt("Hangi tag'i bulmak istiyorsun?", "h2");
36
36
37
-
let regexp =newRegExp(`<${tag}>`); //same as /<h2>/ if answered "h2" in the prompt above
37
+
let regexp =newRegExp(`<${tag}>`); // yukarıdaki prompt'a "h2" cevabı verildiyse, /<h2>/ ile aynı olur.
38
38
```
39
39
40
-
## Flags
40
+
## İşaretler
41
41
42
-
Regular expressions may have flags that affect the search.
42
+
Düzenli ifadelerde aramayı etkileyen işaretler olabilir.
43
43
44
-
There are only 6 of them in JavaScript:
44
+
JavaScript'te bunlardan sadece 6 tanesi var:
45
45
46
46
`pattern:i`
47
-
: With this flag the search is case-insensitive: no difference between `A`and`a`(see the example below).
47
+
: Bu işaretle arama, büyük/küçük harfe duyarlı değildir: `A`ve`a`arasında fark yoktur (aşağıdaki örneğe bakın).
48
48
49
49
`pattern:g`
50
-
: With this flag the search looks for all matches, without it -- only the first match is returned.
50
+
: Bu işaretle arama, tüm eşleşenleri arar. Eğer g işareti yoksa, sadece ilk eşleme döndürülür.
51
51
52
52
`pattern:m`
53
-
: Multiline mode (covered in the chapter <info:regexp-multiline-mode>).
53
+
: Çok satırlı mod (<info:regexp-multiline-mode> bölümünde ele alınmıştır).
54
54
55
55
`pattern:s`
56
-
: Enables "dotall" mode, that allows a dot `pattern:.`to match newline character `\n` (covered in the chapter <info:regexp-character-classes>).
56
+
: Yeni satır karakteri `\n` ile eşleşmek için noktaya `pattern:.`izin veren “dotall” modunu etkinleştirir. (<info:regexp-character-classes> bölümünde ele alınmıştır).
57
57
58
58
`pattern:u`
59
-
: Enables full unicode support. The flag enables correct processing of surrogate pairs. More about that in the chapter <info:regexp-unicode>.
59
+
: Tam unicode desteğini etkinleştirir. Bu işaret, vekil çiftlerin doğru işlenmesini sağlar. Bununla ilgili daha fazla bilgi <info:regexp-unicode> bölümünde.
60
60
61
61
`pattern:y`
62
-
: "Sticky" mode: searching at the exact position in the text (covered in the chapter <info:regexp-sticky>)
62
+
: “Yapışkan” mod: metindeki tam pozisyonu arar (<info:regexp-sticky> bölümünde ele alınmıştır)
63
63
64
-
```smart header="Colors"
65
-
From here on the color scheme is:
64
+
```smart header="Renkler"
65
+
Buradan itibaren renk şeması şu şekilde olacak:
66
66
67
67
- regexp -- `pattern:red`
68
-
- string (where we search) -- `subject:blue`
69
-
- result -- `match:green`
68
+
- string (aradığımız yer) -- `subject:blue`
69
+
- sonuç -- `match:green`
70
70
```
71
71
72
-
## Searching: str.match
72
+
## Arama: str.match
73
73
74
-
As mentioned previously, regular expressions are integrated with string methods.
74
+
Daha önce de belirtildiği gibi, düzenli ifadeler string metotlarına entegre edilmiştir.
75
75
76
-
The method `str.match(regexp)`finds all matches of `regexp`in the string `str`.
76
+
`str.match(regexp)`metodu `regexp`ile `str` stringindeki tüm eşleşmeleri bulur.
77
77
78
-
It has 3 working modes:
78
+
3 çalışma modu vardır:
79
+
80
+
1. Düzenli ifadede `pattern:g` işareti varsa, tüm eşleşmelerden oluşan bir dizi döndürür:
79
81
80
-
1. If the regular expression has flag `pattern:g`, it returns an array of all matches:
81
82
```js run
82
83
let str ="We will, we will rock you";
83
84
84
-
alert( str.match(/we/gi) ); // We,we (an array of 2 substrings that match)
85
+
alert( str.match(/we/gi) ); // We,we (eşleşen 2 string'den oluşan bir dizi)
85
86
```
86
-
Please note that both `match:We`and `match:we` are found, because flag `pattern:i`makes the regular expression case-insensitive.
87
+
Hem `match:We`hem de `match:we`'nin bulunduğuna dikkat edin, çünkü `pattern:i` işareti aramayı büyük/küçük harfe duyarsız hale getirir.
87
88
88
-
2.If there's no such flag it returns only the first match in the form of an array, with the full match at index `0` and some additional details in properties:
89
+
2. Eğer `pattern:g` işareti yoksa, yalnızca ilk eşleşmeyi döndürür. Dönen ifade bir dizi formundadır. İlk eşleşme dizininin `0` indeksinde yer alır ve dizinin bazı ek ayrıntılar sağlayan property'leri vardır:
89
90
```js run
90
91
let str = "We will, we will rock you";
91
92
92
-
let result = str.match(/we/i); // without flag g
93
+
let result = str.match(/we/i); // g işareti olmadan
93
94
94
-
alert( result[0] ); // We (1st match)
95
+
alert( result[0] ); // We (ilk eşleşme)
95
96
alert( result.length ); // 1
96
97
97
98
// Details:
98
-
alert( result.index ); // 0 (position of the match)
99
-
alert( result.input ); // We will, we will rock you (source string)
alert( result.input ); // We will, we will rock you (kaynak string)
100
101
```
101
-
The array may have other indexes, besides `0` if a part of the regular expression is enclosed in parentheses. We'll cover that in the chapter <info:regexp-groups>.
102
+
Düzenli ifadenin bir kısmı parantez içine alınmışsa dizinin `0`dışında başka indeksleri de olabilir. Bunu, <info:regexp-groups> bölümünde ele alacağız.
102
103
103
-
3.And, finally, if there are no matches, `null`is returned (doesn't matter if there's flag `pattern:g`or not).
104
+
3.Son olarak, eşleşme yoksa `null`döndürülür (`pattern:g`işareti olup olmadığı önemli değildir).
104
105
105
-
This a very important nuance. If there are no matches, we don't receive an empty array, but instead receive `null`. Forgetting about that may lead to errors, e.g.:
106
+
Bu çok önemli bir nüans. Eşleşme yoksa boş bir dizi almıyoruz, bunun yerine `null` alıyoruz. Bunu unutmak hatalara neden olabilir, örneğin:
106
107
107
108
```js run
108
109
let matches = "JavaScript".match(/HTML/); // = null
109
110
110
111
if (!matches.length) { // Error: Cannot read property 'length' of null
111
-
alert("Error in the line above");
112
+
alert("Yukardaki satırda hata var");
112
113
}
113
114
```
114
115
115
-
If we'd like the result to always be an array, we can write it this way:
116
+
Sonucun her zaman bir dizi olmasını istiyorsak, bunu şu şekilde yazabiliriz:
116
117
117
118
```js run
118
119
let matches = "JavaScript".match(/HTML/)*!* || []*/!*;
119
120
120
121
if (!matches.length) {
121
-
alert("No matches"); // now it works
122
+
alert("Eşleşme yok"); // şimdi çalışıyor
122
123
}
123
124
```
124
125
125
-
## Replacing:str.replace
126
+
## Yer değiştirme:str.replace
126
127
127
-
The method `str.replace(regexp, replacement)`replaces matches found using `regexp`instring `str`with`replacement` (all matches if there's flag `pattern:g`, otherwise, only the first one).
128
+
`str.replace(regexp, yeni_str)`metodu, string `str`'de `regexp` kullanılarak bulunan eşleşmeleri `yeni_str` ile değiştirir (`pattern:g` işareti varsa tüm eşleşmeler, aksi takdirde yalnızca ilk olanı).
128
129
129
-
For instance:
130
+
Örneğin:
130
131
131
132
```js run
132
133
// no flag g
@@ -136,26 +137,27 @@ alert( "We will, we will".replace(/we/i, "I") ); // I will, we will
136
137
alert( "We will, we will".replace(/we/ig, "I") ); // I will, I will
137
138
```
138
139
139
-
The second argument is the `replacement` string. We can use special character combinations in it to insert fragments of the match:
140
+
İkinci argüman, `yeni_str` bulunan eşlemenin yerine geçen string'dir. Eşleşmenin parçalarını eklemek için özel karakter kombinasyonları kullanabiliriz:
140
141
141
-
| Symbols | Action in the replacement string |
142
+
|Semboller|Değiştirilen yeni_str'de yapılan eylem |
142
143
|--------|--------|
143
-
|`$&`|inserts the whole match|
144
-
|<code>$`</code>|inserts a part of the string before the match|
145
-
|`$'`|inserts a part of the string after the match|
146
-
|`$n`|if `n`is a 1-2 digit number, then it inserts the contents of n-th parentheses, more about it in the chapter <info:regexp-groups>|
147
-
|`$<name>`|inserts the contents of the parentheses with the given `name`, more about it in the chapter <info:regexp-groups>|
148
-
|`$$`|inserts character `$` |
144
+
|`$&`|tüm eşleşmeyi ekler|
145
+
|<code>$`</code>|string'in eşleşmeden önce gelen kısmını ekler|
146
+
|`$'`|string'in eşleşmeden sonra gelen kısmını ekler|
147
+
|`$n`|`n` 1-2 basamaklı bir sayıysa, n. parantezlerin içeriğini ekler, bununla ilgili daha fazla bilgi <info:regexp-groups> bölümünde|
148
+
|`$<isim>`|`isim` adı verilen parantezlerin içeriğini ekler, daha fazlası <info:regexp-groups> bölümünde|
149
+
|`$$`|`$` karakterini ekler|
149
150
150
-
An example with `pattern:$&`:
151
+
`pattern:$&` ile bir örnek::
151
152
152
153
```js run
153
154
alert( "I love HTML".replace(/HTML/, "$& and JavaScript") ); // I love HTML and JavaScript
154
155
```
155
156
156
-
## Testing: regexp.test
157
+
## Test: regexp.test
158
+
159
+
`regexp.test(str)` metodu en az bir eşleşme arar, eşleşme bulunursa `true` değerini döndürür, aksi takdirde `false` değerini döndürür.
157
160
158
-
The method `regexp.test(str)` looks for at least one match, if found, returns `true`, otherwise `false`.
159
161
160
162
```js run
161
163
let str = "I love JavaScript";
@@ -164,14 +166,14 @@ let regexp = /LOVE/i;
164
166
alert( regexp.test(str) ); // true
165
167
```
166
168
167
-
Later in this chapter we'll study more regular expressions, walk through more examples, and also meet other methods.
169
+
Bu bölümün ilerleyen kısımlarında düzenli ifadeler üzerinde daha fazla çalışacağız, daha fazla örnek üzerinde duracağız ve diğer metotlarla da karşılaşacağız.
168
170
169
-
Full information about the methods is given in the article <info:regexp-methods>.
171
+
Metotlar hakkında tam bilgi <info:regexp-methods> makalesinde verilmiştir.
170
172
171
-
## Summary
173
+
## Özet
172
174
173
-
- A regular expression consists of a pattern and optional flags: `pattern:g`, `pattern:i`, `pattern:m`, `pattern:u`, `pattern:s`, `pattern:y`.
174
-
- Without flags and special symbols (that we'll study later), the search by a regexp is the same as a substring search.
175
-
- The method `str.match(regexp)`looks for matches: all of them if there's `pattern:g`flag, otherwise, only the first one.
176
-
- The method `str.replace(regexp, replacement)`replaces matches found using `regexp`with `replacement`: all of them if there's `pattern:g`flag, otherwise only the first one.
177
-
- The method `regexp.test(str)`returns `true` if there's at least one match, otherwise, it returns`false`.
175
+
- Düzenli ifade bir kalıp ve isteğe bağlı işaretlerden oluşur: `pattern:g`, `pattern:i`, `pattern:m`, `pattern:u`, `pattern:s`, `pattern:y`.
176
+
- İşaretler ve özel semboller olmadan (daha sonra inceleyeceğiz) düzenli ifadelerle arama bir substring aramasıyla aynıdır.
- `str.replace(regexp, yeni_str)` metodu, `regexp` kullanılarak bulunan eşleşmeleri `yeni_str` ile değiştirir: `pattern:g` işareti varsa tümünü, aksi takdirde yalnızca ilkini değiştirir.
179
+
- `regexp.test(str)` metodu en az bir eşleşme varsa `true` değerini döndürür, aksi takdirde `false` değerini döndürür.
0 commit comments