File tree Expand file tree Collapse file tree
9-regular-expressions/04-regexp-anchors Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- # Anchors: string start ^ and end $
1+ # لنگرها: رشته شروع ^ و پایان $
22
3- The caret ` pattern:^ ` and dollar ` pattern:$ ` characters have special meaning in a regexp. They are called "anchors" .
3+ کاراکترهای ` pattern:^ ` و دلار ` pattern:$ ` معنای خاصی در یک regexp دارند. به آنها "لنگر" می گویند .
44
55The caret ` pattern:^ ` matches at the beginning of the text, and the dollar ` pattern:$ ` -- at the end.
6+ ` pattern:^ ` در ابتدای متن و ` pattern:$ ` دلاری -- در پایان متن مطابقت دارد.
67
7- For instance, let's test if the text starts with ` Mary ` :
8-
8+ به عنوان مثال، بیایید آزمایش کنیم که آیا متن با ` Mary ` شروع می شود یا خیر:
99``` js run
1010let str1 = " Mary had a little lamb" ;
11- alert ( / ^ Mary/ .test (str1) ); // true
11+ alert ( / ^ Mary/ .test (str1) ); // درست
1212```
1313
14- The pattern ` pattern:^Mary ` means: "string start and then Mary".
14+ الگوی ` pattern:^Mary ` به معنای "شروع رشته و سپس Mary" است .
1515
16- Similar to this, we can test if the string ends with ` snow ` using ` pattern: snow$ ` :
16+ مشابه این، میتوانیم با استفاده از ` pattern:snow$ ` آزمایش کنیم که آیا رشته به ` snow ` ختم میشود :
1717
1818``` js run
1919let str1 = " its fleece was white as snow" ;
20- alert ( / snow$ / .test (str1) ); // true
20+ alert ( / snow$ / .test (str1) ); // درست
2121```
2222
2323In these particular cases we could use string methods ` startsWith/endsWith ` instead. Regular expressions should be used for more complex tests.
You can’t perform that action at this time.
0 commit comments