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
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -123,11 +123,11 @@ let regexp = new RegExp(`<${tag}>`); // مانند /<h2>/ اگر در اعلان
123
123
}
124
124
```
125
125
126
-
## Replacing:str.replace
126
+
## جایگزین کردن:str.replace
127
127
128
-
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، replacement)`تطابق هایی را که با استفاده از `regexp`در رشته`str`یافت میشود را با `replacement`جایگزین میکند (همه منطبق هستند اگر پرچم`pattern:g` وجود داشته باشد، در غیر این صورت، فقط اولین مورد است).
129
129
130
-
For instance:
130
+
برای مثال:
131
131
132
132
```js run
133
133
// no flag g
@@ -137,18 +137,18 @@ alert( "We will, we will".replace(/we/i, "I") ); // I will, we will
137
137
alert( "We will, we will".replace(/we/ig, "I") ); // I will, I will
138
138
```
139
139
140
-
The second argument is the `replacement` string. We can use special character combinations in it to insert fragments of the match:
140
+
آرگومان دوم رشته، `replacement(جایگزینی)` است. میتوانیم از ترکیب کاراکتر های ویژه در آن برای درج قطعاتی از تطابق استفاده کنیم:
141
141
142
-
| Symbols | Action in the replacement string |
142
+
|نماد|عمل در رشته جایگزین|
143
143
|--------|--------|
144
-
|`$&`|inserts the whole match|
145
-
|<code>$`</code>|inserts a part of the string before the match|
146
-
|`$'`|inserts a part of the string after the match|
147
-
|`$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>|
148
-
|`$<name>`|inserts the contents of the parentheses with the given `name`, more about it in the chapter <info:regexp-groups>|
149
-
|`$$`|inserts character `$` |
150
-
151
-
An example with`pattern:$&`:
144
+
|`$&`|کل تطابق را درج می کند|
145
+
|<code>$`</code>|قسمتی از رشته را قبل از تطابق وارد می کند|
146
+
|`$'`|قسمتی از رشته را بعد از تطابق وارد می کند|
147
+
|`$n`|اگر`n`یک عدد1-2رقمی باشد، محتویات پرانتزهای n را درج می کند، اطلاعات بیشتر در مورد آن در فصل<info:regexp-groups>|
148
+
|`$<name>`|محتویات پرانتز را با `name` داده شده درج می کند، اطلاعات بیشتر در مورد آن در فصل<info:regexp-groups>|
149
+
|`$$`|کاراکتر "$" را درج می کند|
150
+
151
+
مثالی برای`pattern:$&`:
152
152
153
153
```js run
154
154
alert( "I love HTML".replace(/HTML/, "$& and JavaScript") ); // I love HTML and JavaScript
0 commit comments