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
Copy file name to clipboardExpand all lines: 9-regular-expressions/01-regexp-introduction/article.md
+8-7Lines changed: 8 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -85,7 +85,7 @@ let regexp = new RegExp(`<${tag}>`); // مانند /<h2>/ اگر در اعلان
85
85
```
86
86
لطفاً توجه کنید که `match:We` و `match:we` نتیجه یکسانی میدهند، زیرا پرچم `pattern:i` باعث میشود که عبارت باقاعده به حروف بزرگ و کوچک حساس نباشد.
87
87
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:
88
+
2.اگر چنین پرچمی وجود نداشته باشد، فقط اولین تطابق را در یک آرایه، با تطابق کامل در ایندکس `0` و برخی جزئیات اضافی در ویژگی ها بر می گرداند:
89
89
```js run
90
90
let str = "We will, we will rock you";
91
91
@@ -95,14 +95,15 @@ let regexp = new RegExp(`<${tag}>`); // مانند /<h2>/ اگر در اعلان
95
95
alert( result.length ); // 1
96
96
97
97
// Details:
98
-
alert( result.index ); // 0 (position of the match)
99
-
alert( result.input ); // We will, we will rock you (source string)
98
+
alert( result.index ); // 0 (موقعیت تطابق)
99
+
alert( result.input ); // We will, we will rock you (رشته منبع)
100
100
```
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>.
101
+
102
+
اگر بخشی از عبارت باقاعده در داخل پرانتز قرار بگیرد، ممکن است آرایه، ایندکس های دیگری در کنار ایندکس `0` نیز داشته باشد. ما آن را در فصل <info:regexp-groups> پوشش خواهیم داد.
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.و در نهایت، اگر هیچ تطابقی وجود نداشته باشد، `null`بر می گرداند. (فرقی نمیکند که پرچم `pattern:g`وجود داشته باشد یا خیر).
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
+
این یک فرق ریز و بسیار مهم است. اگر هیچ تطابقی وجود نداشته باشد، یک آرایه خالی دریافت نمیکنیم، بلکه `null` دریافت می کنیم. فراموش کردن آن ممکن است منجر به خطاهایی شود، به عنوان مثال:
106
107
107
108
```js run
108
109
let matches = "JavaScript".match(/HTML/); // = null
@@ -112,7 +113,7 @@ let regexp = new RegExp(`<${tag}>`); // مانند /<h2>/ اگر در اعلان
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
+
اگر میخواهیم نتیجه همواره یک آرایه باشد، می توانیم آن را به این صورت بنویسیم:
116
117
117
118
```js run
118
119
let matches = "JavaScript".match(/HTML/)*!* || []*/!*;
0 commit comments