Skip to content

Commit b669507

Browse files
authored
Merge pull request #259 from EhsanShahbazii/master
Multiline mode of anchors ^ $, flag "m"
2 parents 5ab9a81 + f9e1676 commit b669507

File tree

1 file changed

+24
-24
lines changed
  • 9-regular-expressions/05-regexp-multiline-mode

1 file changed

+24
-24
lines changed
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# Multiline mode of anchors ^ $, flag "m"
1+
# حالت چند خطی anchors ^ $، flag "m"
22

3-
The multiline mode is enabled by the flag `pattern:m`.
3+
حالت چند خطی با flag `pattern:m` فعال می شود.
44

5-
It only affects the behavior of `pattern:^` and `pattern:$`.
5+
فقط بر رفتار `^:pattern` و `$:pattern` تأثیر می گذارد.
66

7-
In the multiline mode they match not only at the beginning and the end of the string, but also at start/end of line.
7+
در حالت چند خطی، نه تنها در ابتدا و انتهای رشته، بلکه در شروع/پایان خط نیز مطابقت دارند.
88

9-
## Searching at line start ^
9+
## جستجو در شروع خط ^
1010

11-
In the example below the text has multiple lines. The pattern `pattern:/^\d/gm` takes a digit from the beginning of each line:
11+
در مثال زیر متن دارای چندین خط است. الگوی `pattern:/^\d/gm` از ابتدای هر خط یک رقم می گیرد:
1212

1313
```js run
1414
let str = `1st place: Winnie
@@ -20,7 +20,7 @@ console.log( str.match(/^\d/gm) ); // 1, 2, 3
2020
*/!*
2121
```
2222

23-
Without the flag `pattern:m` only the first digit is matched:
23+
بدون flag `pattern:m` تنها رقم اول مطابقت دارد:
2424

2525
```js run
2626
let str = `1st place: Winnie
@@ -32,19 +32,19 @@ console.log( str.match(/^\d/g) ); // 1
3232
*/!*
3333
```
3434

35-
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` فقط در ابتدای متن و در حالت چند خطی - در ابتدای هر خط مطابقت دارد.
3636

3737
```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\` قرار دارند مطابقت دارد.
3939
40-
And at the text start.
40+
و در شروع متن.
4141
```
4242

43-
## Searching at line end $
43+
## جستجو در انتهای خط $
4444

45-
The dollar sign `pattern:$` behaves similarly.
45+
علامت دلار `$:pattern` رفتار مشابهی دارد.
4646

47-
The regular expression `pattern:\d$` finds the last digit in every line
47+
عبارت منظم `$pattern:\d` آخرین رقم را در هر خط پیدا می کند
4848

4949
```js run
5050
let str = `Winnie: 1
@@ -54,21 +54,21 @@ Eeyore: 3`;
5454
console.log( str.match(/\d$/gm) ); // 1,2,3
5555
```
5656

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` علامت دلار فقط با انتهای کل متن مطابقت دارد، بنابراین فقط آخرین رقم پیدا می‌ شود.
5858

5959
```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\" قرار دارند، مطابقت دارد.
6161
62-
And at the text end.
62+
و در انتهای متن.
6363
```
6464

65-
## Searching for \n instead of ^ $
65+
## جستجو برای \n به جای ^ $
6666

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\` استفاده کنیم.
6868

69-
What's the difference? Let's see an example.
69+
تفاوت در چیست؟ بیایید یک مثال را ببینیم.
7070

71-
Here we search for `pattern:\d\n` instead of `pattern:\d$`:
71+
در اینجا ما `pattern:\d\n` را به جای `$pattern:\d` جستجو می کنیم:
7272

7373
```js run
7474
let str = `Winnie: 1
@@ -78,10 +78,10 @@ Eeyore: 3`;
7878
console.log( str.match(/\d\n/g) ); // 1\n,2\n
7979
```
8080

81-
As we can see, there are 2 matches instead of 3.
81+
همانطور که می بینیم به جای 3 شباهت 2 شباهت وجود دارد.
8282

83-
That's because there's no newline after `subject:3` (there's text end though, so it matches `pattern:$`).
83+
دلیلش این است که بعد از `3:subject` خط جدیدی وجود ندارد (البته پایان متن وجود دارد، بنابراین با `$:pattern` مطابقت دارد.
8484

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\` یک کاراکتر است، بنابراین بخشی از نتیجه می‌ شود.
8686

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

Comments
 (0)