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/04-regexp-anchors/article.md
+9-10Lines changed: 9 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,28 +20,27 @@ let str1 = "its fleece was white as snow";
20
20
alert(/snow$/.test(str1) ); // درست
21
21
```
22
22
23
-
In these particular cases we could use string methods `startsWith/endsWith`instead. Regular expressions should be used for more complex tests.
23
+
در این موارد خاص، میتوانیم به جای آن از روشهای رشتهای `startsWith/endsWith`استفاده کنیم. برای تست های پیچیده تر باید از عبارات منظم استفاده شود.
24
24
25
-
## Testing for a full match
25
+
## تست برای یک مسابقه کامل
26
26
27
-
Both anchors together `pattern:^...$` are often used to test whether or not a string fully matches the pattern. For instance, to check if the user input is in the right format.
27
+
هر دو لنگر با هم `$...^:pattern` اغلب برای آزمایش اینکه آیا یک رشته کاملاً با الگو مطابقت دارد یا نه استفاده می شود. به عنوان مثال، برای بررسی اینکه آیا ورودی کاربر در قالب مناسب است یا خیر.
28
28
29
-
Let's check whether or not a string is a time in `12:34` format. That is: two digits, then a colon, and then another two digits.
30
-
31
-
In regular expressions language that's `pattern:\d\d:\d\d`:
29
+
بیایید بررسی کنیم که آیا یک رشته زمان در قالب `12:34` است یا خیر. یعنی: دو رقم، سپس یک دونقطه، و سپس دو رقم دیگر.
32
30
31
+
در زبان عبارات معمولی `pattern:\d\d:\d\d` است:
33
32
```js run
34
33
let goodInput ="12:34";
35
34
let badInput ="12:345";
36
35
37
36
let regexp =/^\d\d:\d\d$/;
38
-
alert( regexp.test(goodInput) ); //true
39
-
alert( regexp.test(badInput) ); //false
37
+
alert( regexp.test(goodInput) ); //درست
38
+
alert( regexp.test(badInput) ); //نادرست
40
39
```
41
40
42
-
Here the match for `pattern:\d\d:\d\d`must start exactly after the beginning of the text `pattern:^`, and the end `pattern:$` must immediately follow.
41
+
در اینجا تطبیق `pattern:\d\d:\d\d`باید دقیقاً بعد از ابتدای متن `^:pattern` شروع شود و انتهای `$:pattern` باید بلافاصله دنبال شود.
43
42
44
-
The whole string must be exactly in this format. If there's any deviation or an extra character, the result is `false`.
43
+
کل رشته باید دقیقاً در این قالب باشد. اگر انحراف یا یک کاراکتر اضافی وجود داشته باشد، نتیجه `نادرست` است.
45
44
46
45
Anchors behave differently if flag `pattern:m` is present. We'll see that in the next article.
0 commit comments