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
That's because by default a caret `pattern:^` only matches at the beginning of the text, and in the multiline mode -- at the start of any line.
35
+
دلیلش این است که به طور پیش فرض یک `^:pattern` فقط در ابتدای متن و در حالت چند خطی - در ابتدای هر خط مطابقت دارد.
36
36
37
37
```smart
38
-
"Start of a line" formally means "immediately after a line break": the test `pattern:^` in multiline mode matches at all positions preceded by a newline character `\n`.
38
+
"شروع یک خط" به طور رسمی به معنای "بلافاصله پس از شکست خط" است: آزمایش "^:pattern" در حالت چند خطی با همه موقعیت هایی که بعد از یک کاراکترِ خط جدید `n\` قرار دارند مطابقت دارد.
39
39
40
-
And at the text start.
40
+
و در شروع متن.
41
41
```
42
42
43
-
## Searching at line end $
43
+
## جستجو در انتهای خط $
44
44
45
-
The dollar sign `pattern:$` behaves similarly.
45
+
علامت دلار `$:pattern` رفتار مشابهی دارد.
46
46
47
-
The regular expression `pattern:\d$` finds the last digit in every line
47
+
عبارت منظم `$pattern:\d` آخرین رقم را در هر خط پیدا می کند
48
48
49
49
```js run
50
50
let str =`Winnie: 1
@@ -54,21 +54,21 @@ Eeyore: 3`;
54
54
console.log( str.match(/\d$/gm) ); // 1,2,3
55
55
```
56
56
57
-
Without the flag `pattern:m`, the dollar `pattern:$` would only match the end of the whole text, so only the very last digit would be found.
57
+
بدون flag `pattern:m` و `$:pattern` علامت دلار فقط با انتهای کل متن مطابقت دارد، بنابراین فقط آخرین رقم پیدا می شود.
58
58
59
59
```smart
60
-
"End of a line" formally means "immediately before a line break": the test `pattern:$` in multiline mode matches at all positions succeeded by a newline character `\n`.
60
+
"پایان یک خط" به طور رسمی به معنای "بلافاصله قبل از شکست خط" است: تست "$:pattern" در حالت چند خطی با همه موقعیتهایی که قبل از یک کاراکتر خط جدید "n\" قرار دارند، مطابقت دارد.
61
61
62
-
And at the text end.
62
+
و در انتهای متن.
63
63
```
64
64
65
-
## Searching for \n instead of ^ $
65
+
## جستجو برای \n به جای ^ $
66
66
67
-
To find a newline, we can use not only anchors `pattern:^` and `pattern:$`, but also the newline character `\n`.
67
+
برای یافتن یک خط جدید، می توانیم نه تنها از anchorهای `^:pattern` و `$:pattern`، بلکه از کاراکتر خط جدید `n\` استفاده کنیم.
68
68
69
-
What's the difference? Let's see an example.
69
+
تفاوت در چیست؟ بیایید یک مثال را ببینیم.
70
70
71
-
Here we search for `pattern:\d\n`instead of `pattern:\d$`:
71
+
در اینجا ما `pattern:\d\n`را به جای `$pattern:\d` جستجو می کنیم:
72
72
73
73
```js run
74
74
let str =`Winnie: 1
@@ -78,10 +78,10 @@ Eeyore: 3`;
78
78
console.log( str.match(/\d\n/g) ); // 1\n,2\n
79
79
```
80
80
81
-
As we can see, there are 2 matches instead of 3.
81
+
همانطور که می بینیم به جای 3 شباهت 2 شباهت وجود دارد.
82
82
83
-
That's because there's no newline after `subject:3` (there's text end though, so it matches `pattern:$`).
83
+
دلیلش این است که بعد از `3:subject` خط جدیدی وجود ندارد (البته پایان متن وجود دارد، بنابراین با `$:pattern` مطابقت دارد.
84
84
85
-
Another difference: now every match includes a newline character `match:\n`. Unlike the anchors `pattern:^``pattern:$`, that only test the condition (start/end of a line), `\n` is a character, so it becomes a part of the result.
85
+
تفاوت دیگر: اکنون هر تطابق شامل یک کاراکتر خط جدید `match:\n` است. برخلاف `$:pattern` و `^:pattern` که فقط شرط (شروع/پایان یک خط) را آزمایش می کنند، `n\` یک کاراکتر است، بنابراین بخشی از نتیجه می شود.
86
86
87
-
So, a `\n` in the pattern is used when we need newline characters in the result, while anchors are used to find something at the beginning/end of a line.
87
+
بنابراین، زمانی که به کاراکترهای خط جدید در نتیجه نیاز داشته باشیم، از `n\` در الگو استفاده می شود، در حالی که از anchorها برای یافتن چیزی در ابتدا/پایان یک خط استفاده می شود.
0 commit comments