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
Ne yazık ki, eşleşmenin belirli bir konumdan başlaması gerektiğini belirtmenin bir yolu yoktur (`indexOf`'deki ikinci argümanla yaptığımız gibi), bu genellikle kullanışlı olurdu.
633
633
634
-
## The lastIndex property
634
+
## lastIndex özelliği
635
635
636
636
{{index "exec method", "regular expression"}}
637
637
638
-
The `exec`method similarly does not provide a convenient way to start searching from a given position in the string. But it does provide an *in*convenient way.
638
+
`exec`metodu benzer şekilde, dizinde belirli bir konumdan aramaya başlamanın kolay bir yolunu sağlamaz. Ancak kolay *olmayan*, zor bir yolunu sağlar.
Regular expression objects have properties. One such property is `source`, which contains the string that expression was created from. Another property is `lastIndex`, which controls, in some limited circumstances, where the next match will start.
642
+
Düzenli ifade nesnelerinin özellikleri vardır. Bunlardan biri `source` özelliğidir ve değerinde bu ifadenin oluşturulduğu dizeyi barındırır. Başka bir özellik de `lastIndex`'tir, bazı sınırlı durumlarda bir sonraki eşleşmenin nereden başlayacağını kontrol eder.
Those circumstances are that the regular expression must have the global (`g`) or sticky (`y`) option enabled, and the match must happen through the `exec` method. Again, a less confusing solution would have been to just allow an extra argument to be passed to `exec`, but confusion is an essential feature of JavaScript's regular expression interface.
646
+
Bu durumlar, düzenli ifadenin global (`g`) veya yapışkan (`y`) seçeneğinin etkinleştirilmiş olması ve eşleşmenin `exec` metodu aracılığıyla gerçekleşmiş olması gereklidir. Tabii, daha az kafa karışıklığına sebep olmak için `exec` metoduna ekstra bir argümanın verilmesine izin verilmesi daha iyi olurdu, ancak karışıklık JavaScript'in düzenli ifade arayüzünün temel bir özelliğidir.
If the match was successful, the call to `exec`automatically updates the`lastIndex`property to point after the match. If no match was found, `lastIndex`is set back to zero, which is also the value it has in a newly constructed regular expression object.
660
+
Eşleşme başarılı olduysa, `exec`çağrısı otomatik olarak`lastIndex`özelliğini eşleşmenin sonrasına işaret edecek şekilde günceller. Eğer bir eşleşme bulunamadıysa, `lastIndex`sıfıra, aynı zamanda yeni oluşturulan bir düzenli ifade nesnesinin sahip olduğu değere geri döner.
661
661
662
-
The difference between the global and the sticky options is that, when sticky is enabled, the match will succeed only if it starts directly at `lastIndex`, whereas with global, it will search ahead for a position where a match can start.
662
+
Global ve yapışkan seçenekler arasındaki fark, yapışkan etkinleştirildiğinde, eşleşme ancak `lastIndex`'te doğrudan başlaması durumunda başarılı olacağıdır, global kullanıldığındaysa, bir eşleşmenin başlayabileceği bir konumu arar.
When using a shared regular expression value for multiple `exec` calls, these automatic updates to the `lastIndex`property can cause problems. Your regular expression might be accidentally starting at an index that was left over from a previous call.
675
+
Birden fazla `exec` çağrısı için paylaşılan bir düzenli ifade değeri kullanırken, bu otomatik güncellemeler `lastIndex`özelliğinin değerinde sorunlara neden olabilir. Düzenli ifadeniz yanlışlıkla önceki bir çağrıdan kalan index değerinden başlayabilir.
Another interesting effect of the global option is that it changes the way the `match`method on strings works. When called with a global expression, instead of returning an array similar to that returned by `exec`, `match` will find _all_ matches of the pattern in the string and return an array containing the matched strings.
687
+
Global seçeneğin başka bir ilginç etkisi de, dizeler üzerindeki `match`metodunun çalışma şeklini değiştirmesidir. Global bir ifade ile çağrıldığında, `exec` tarafından döndürülen diziye benzer bir dizi döndürmek yerine, `match`, dizedeki desenin _tüm_ eşleşmelerini bulur ve eşleşen dizeleri içeren bir dizi döndürür.
688
688
689
689
```
690
690
console.log("Banana".match(/an/g));
691
691
// → ["an", "an"]
692
692
```
693
693
694
-
So be cautious with global regular expressions. The cases where they are necessary—calls to `replace`and places where you want to explicitly use `lastIndex`—are typically the only places where you want to use them.
694
+
Dolayısıyla, global düzenli ifadelerle dikkatli olun. Bunların gerekli olduğu durumlar - `replace`çağrıları ve açıkça `lastIndex`'i kullanmak istediğiniz yerler- genellikle bunları kullanmak istediğiniz tek yerlerdir.
To conclude the chapter, we'll look at a problem that calls for ((regular expression))s. Imagine we are writing a program to automatically collect information about our enemies from the ((Internet)). (We will not actually write that program here, just the part that reads the ((configuration)) file. Sorry.) The configuration file looks like this:
722
+
Bölümü sonlandırmak için, ((düzenli ifade))lere ihtiyaç duyulan bir soruna bakacağız. Düşmanlarımız hakkında ((internet))ten bilgi toplamak için bir program yazdığımızı hayal edin. (Burada aslında bu programı yazmayacağız, sadece ((konfigürasyon)) dosyasını okuyan kısmı yazacağız. Maalesef.) Konfigürasyon dosyası şöyle görünüyor:
The exact rules for this format (which is a widely used format, usually called an _INI_ file) are as follows:
743
+
Bu biçim için kesin kurallar (genellikle _INI_ dosyası olarak adlandırılan yaygın bir biçimdir) şunlardır:
744
744
745
-
-Blank lines and lines starting with semicolons are ignored.
745
+
-Boş satırlar ve noktalı virgül ile başlayan satırlar yoksayılır.
746
746
747
-
-Lines wrapped in `[` and `]` start a new ((section)).
747
+
-[ ve ] içinde sarmalanan satırlar yeni bir ((bölüm)) başlatır.
748
748
749
-
-Lines containing an alphanumeric identifier followed by an `=` character add a setting to the current section.
749
+
-Alfasayısal bir tanımlayıcıyı takiben bir `=`karakter içeren satırlar, mevcut bölüme bir ayar ekler.
750
750
751
-
-Anything else is invalid.
751
+
-Bunlardan başka her şey geçersizdir.
752
752
753
-
Our task is to convert a string like this into an object whose properties hold strings for settings written before the first section header and subobjects for sections, with those subobjects holding the section's settings.
753
+
Görevimiz, böyle bir dizeyi, ilk bölüm başlığından önce yazılan ayarları tutan özelliklere sahip nesneye ve bölümleri tutan alt nesnelerleri barındıran bir nesneye dönüştürmektir.
Since the format has to be processed ((line)) by line, splitting up the file into separate lines is a good start. We saw the `split`method in [Chapter ?](data#split). Some operating systems, however, use not just a newline character to separate lines but a carriage return character followed by a newline (`"\r\n"`). Given that the `split`method also allows a regular expression as its argument, we can use a regular expression like `/\r?\n/`to split in a way that allows both`"\n"`and `"\r\n"`between lines.
757
+
Biçimin ((satır)) satır işlenmesini gerektirdiğinden, dosyayı ayrı satırlara ayırmak iyi bir başlangıçtır. `split`metodunu [bölüm ?](data#split) içinde gördük. Ancak, bazı işletim sistemleri, sadece bir yeni satır karakterini değil, bir taşıma dönüş karakteri ve ardından bir yeni satır karakteri (`"\r\n"`) kullanır. `split`metodunun da bir düzenli ifadeyi argüman olarak almasına izin verildiğinden, `/\r?\n/`gibi bir düzenli ifade kullanarak, satırlar arasında hem`"\n"`hem de `"\r\n"`izin veren bir şekilde bölebiliriz.
758
758
759
759
```{startCode: true}
760
760
function parseINI(string) {
@@ -783,25 +783,25 @@ city=Tessaloniki`));
783
783
784
784
{{index "parseINI function", parsing}}
785
785
786
-
The code goes over the file's lines and builds up an object. Properties at the top are stored directly into that object, whereas properties found in sections are stored in a separate section object. The `section`binding points at the object for the current section.
786
+
Kod, dosyanın satırlarını geçer ve bir nesne oluşturur. Üstteki özellikler doğrudan bu nesneye depolanırken, bölümlerde bulunan özellikler ayrı bir bölüm nesnesine depolanır. `section`bağlantısı, mevcut bölüm için olan nesneye işaret eder.
787
787
788
-
There are two kinds of significant lines—section headers or property lines. When a line is a regular property, it is stored in the current section. When it is a section header, a new section object is created, and `section`is set to point at it.
788
+
İki tür önemli satır vardır - bölüm başlıkları veya özellik satırları. Bir satır normal bir özellik olduğunda, mevcut bölüme depolanır. Bir bölüm başlığı olduğunda, yeni bir bölüm nesnesi oluşturulur ve `section`bunua işaret etmesi için ayarlanır.
Note the recurring use of `^`and`$`to make sure the expression matches the whole line, not just part of it. Leaving these out results in code that mostly works but behaves strangely for some input, which can be a difficult bug to track down.
792
+
`^`ve`$`işaretinin ifadenin sadece bir parçası değil, tüm satırı eşleştirmesini sağlamak için tekrar tekrar kullanılmasına dikkat edin. Bunları bırakmak, çoğunlukla işe yarayan ancak bazı girdiler için garip davranan bir kod sonucu ile sonuçlanır, bu da takip edilmesi zor bir hatadır.
The pattern `if (match = string.match(...))`makes use of the fact that the value of an ((assignment)) expression (`=`) is the assigned value. You often aren't sure that your call to `match`will succeed, so you can access the resulting object only inside an `if`statement that tests for this. To not break the pleasant chain of `else if`forms, we assign the result of the match to a binding and immediately use that assignment as the test for the `if` statement.
796
+
`if (match = string.match(...))`kalıbı, bir ((atama)) ifadesinin (`=`) değerinin atanmış değer olduğu gerçeğinden yararlanır. `match`çağrınızın başarılı olacağından emin olamazsınız, bu yüzden sonucu yalnızca bunu test eden bir `if`ifadesi içinde erişebilirsiniz. `else if`zincirini bozmamak için, eşleşmenin sonucunu bir bağlantıya atar ve hemen bu atamayı `if` ifadesi için test olarak kullanırız.
797
797
798
798
{{index [parentheses, "in regular expressions"]}}
799
799
800
-
If a line is not a section header or a property, the function checks whether it is a comment or an empty line using the expression `/^\s*(;|$)/`to match lines that either contain only space, or space followed by a semicolon (making the rest of the line a comment). When a line doesn't match any of the expected forms, the function throws an exception.
800
+
Bir satır eğer bir bölüm başlığı veya bir özellik değilse, fonksiyon, `/^\s*(;|$)/`ifadesini kullanarak satırın bir yorum veya boş bir satır olup olmadığını kontrol eder. Bir satırın beklenen biçimlerden hiçbirine uymadığı durumda, fonksiyon bir istisna fırlatır.
801
801
802
-
## Code units and characters
802
+
## Kod birimleri ve karakterler
803
803
804
-
Another design mistake that's been standardized, in JavaScript regular expressions, is that by default, operator like `.`or`?`work on code units, as discussed in [Chapter ?](higher_order#code_units), not actual characters. This means characters that are composed of two code units behave strangely.
804
+
JavaScript düzenli ifadelerinde standartlaştırılmış başka bir tasarım hatası da, [bölüm ?](higher_order#code_units) içinde tartışıldığı gibi varsayılan olarak `.`veya`?`gibi operatörlerin gerçek karakterler yerine kod birimleri üzerinde çalışmasıdır. Bu, iki kod biriminden oluşan karakterlerin garip davranmasına neden olur.
The problem is that the 🍎 in the first line is treated as two code units, and the `{3}`part is applied only to the second one. Similarly, the dot matches a single code unit, not the two that make up the rose ((emoji)).
815
+
Sorun, birinci satırdaki 🍎 karakterinin iki kod biriminden oluştuğu şekilde işlenmesidir ve `{3}`kısmının yalnızca ikincisi üzerinde uygulanmasıdır. Benzer şekilde, nokta tek bir kod birimini eşleştirir, gül ((emoji))'sini oluşturan ikiyi değil.
816
816
817
-
You must add the `u` (Unicode) option to your regular expression to make it treat such characters properly.
817
+
Bu tür karakterleri uygun bir şekilde işlemesi için düzenli ifadenize `u` (Unicode) seçeneğini eklemeniz gerekir.
0 commit comments