Skip to content

Commit 50012c8

Browse files
committed
Translate Patterns and flags
1 parent 7105181 commit 50012c8

File tree

1 file changed

+72
-70
lines changed
  • 9-regular-expressions/01-regexp-introduction

1 file changed

+72
-70
lines changed
Lines changed: 72 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,133 @@
1-
# Patterns and flags
1+
# Kalıplar ve işaretler
22

3-
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.
44

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.
66

7-
## Regular Expressions
7+
## Düzenli İfadeler
88

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.
1010

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.
1212

13-
The "long" syntax:
13+
Uzun olan sözdizimi:
1414

1515
```js
16-
regexp = new RegExp("pattern", "flags");
16+
regexp = new RegExp("kalıp", "işaretler");
1717
```
1818

19-
And the "short" one, using slashes `"/"`:
19+
Ve bölme işareti "/" kullanan kısa olanı:
2020

2121
```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)
2424
```
2525

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.
2727

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.
2929

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.
3131

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:
3333

3434
```js
35-
let tag = prompt("What tag do you want to find?", "h2");
35+
let tag = prompt("Hangi tag'i bulmak istiyorsun?", "h2");
3636

37-
let regexp = new RegExp(`<${tag}>`); // same as /<h2>/ if answered "h2" in the prompt above
37+
let regexp = new RegExp(`<${tag}>`); // yukarıdaki prompt'a "h2" cevabı verildiyse, /<h2>/ ile aynı olur.
3838
```
3939

40-
## Flags
40+
## İşaretler
4141

42-
Regular expressions may have flags that affect the search.
42+
Düzenli ifadelerde aramayı etkileyen işaretler olabilir.
4343

44-
There are only 6 of them in JavaScript:
44+
JavaScript'te bunlardan sadece 6 tanesi var:
4545

4646
`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).
4848

4949
`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.
5151

5252
`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).
5454

5555
`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).
5757

5858
`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.
6060

6161
`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)
6363

64-
```smart header="Colors"
65-
From here on the color scheme is:
64+
```smart header="Renkler"
65+
Buradan itibaren renk şeması şu şekilde olacak:
6666
6767
- 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`
7070
```
7171

72-
## Searching: str.match
72+
## Arama: str.match
7373

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.
7575

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.
7777

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:
7981

80-
1. If the regular expression has flag `pattern:g`, it returns an array of all matches:
8182
```js run
8283
let str = "We will, we will rock you";
8384

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)
8586
```
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.
8788
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:
8990
```js run
9091
let str = "We will, we will rock you";
9192
92-
let result = str.match(/we/i); // without flag g
93+
let result = str.match(/we/i); // g işareti olmadan
9394
94-
alert( result[0] ); // We (1st match)
95+
alert( result[0] ); // We (ilk eşleşme)
9596
alert( result.length ); // 1
9697
9798
// Details:
98-
alert( result.index ); // 0 (position of the match)
99-
alert( result.input ); // We will, we will rock you (source string)
99+
alert( result.index ); // 0 (eşlemenin string'deki pozisyonu)
100+
alert( result.input ); // We will, we will rock you (kaynak string)
100101
```
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.
102103

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).
104105

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:
106107

107108
```js run
108109
let matches = "JavaScript".match(/HTML/); // = null
109110
110111
if (!matches.length) { // Error: Cannot read property 'length' of null
111-
alert("Error in the line above");
112+
alert("Yukardaki satırda hata var");
112113
}
113114
```
114115

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:
116117

117118
```js run
118119
let matches = "JavaScript".match(/HTML/)*!* || []*/!*;
119120
120121
if (!matches.length) {
121-
alert("No matches"); // now it works
122+
alert("Eşleşme yok"); // şimdi çalışıyor
122123
}
123124
```
124125

125-
## Replacing: str.replace
126+
## Yer değiştirme: str.replace
126127

127-
The method `str.replace(regexp, replacement)` replaces matches found using `regexp` in string `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ı).
128129
129-
For instance:
130+
Örneğin:
130131
131132
```js run
132133
// no flag g
@@ -136,26 +137,27 @@ alert( "We will, we will".replace(/we/i, "I") ); // I will, we will
136137
alert( "We will, we will".replace(/we/ig, "I") ); // I will, I will
137138
```
138139
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:
140141

141-
| Symbols | Action in the replacement string |
142+
| Semboller | Değiştirilen yeni_str'de yapılan eylem |
142143
|--------|--------|
143-
|`$&`|inserts the whole match|
144-
|<code>$&#096;</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>$&#096;</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|
149150
150-
An example with `pattern:$&`:
151+
`pattern:$&` ile bir örnek::
151152
152153
```js run
153154
alert( "I love HTML".replace(/HTML/, "$& and JavaScript") ); // I love HTML and JavaScript
154155
```
155156
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.
157160
158-
The method `regexp.test(str)` looks for at least one match, if found, returns `true`, otherwise `false`.
159161
160162
```js run
161163
let str = "I love JavaScript";
@@ -164,14 +166,14 @@ let regexp = /LOVE/i;
164166
alert( regexp.test(str) ); // true
165167
```
166168
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.
168170
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.
170172
171-
## Summary
173+
## Özet
172174
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.
177+
- `str.match(regexp)` metodu eşleşmeleri arar: `pattern:g` işareti varsa tümü, aksi takdirde yalnızca birincisini döner.
178+
- `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

Comments
 (0)