1- # Character classes
1+ # کلاس های کاراکتر ( Character classes)
22
3- Consider a practical task -- we have a phone number like ` "+7(903)-123- 45-67" ` , and we need to turn it into pure numbers : ` 79031234567 ` .
3+ یک تسک عملی را در نظر بگیرید -- ما یک شماره تلفن مانند ` "67- 45-123-(903)7+" ` داریم و باید آن را به اعداد خالص تبدیل کنیم : ` 79031234567 ` .
44
5- To do so, we can find and remove anything that's not a number. Character classes can help with that .
5+ برای انجام این تسک، می توانیم هر چیزی را که عدد نیست پیدا و حذف کنیم. کلاس های کاراکتر می تواند در این مورد کمک کند .
66
7- A * character class * is a special notation that matches any symbol from a certain set .
7+ * کلاس کاراکتر * نماد خاصی است که با هر نمادی از یک مجموعه خاص مطابقت دارد .
88
9- For the start, let's explore the "digit" class. It's written as ` pattern:\d ` and corresponds to "any single digit" .
9+ برای شروع، بیایید کلاس "digit" را بررسی کنیم. به صورت ` pattern:\d ` نوشته می شود و با "هر رقمی" مطابقت دارد .
1010
11- For instance, let's find the first digit in the phone number :
11+ به عنوان مثال، بیایید اولین رقم را در شماره تلفن پیدا کنیم :
1212
1313``` js run
1414let str = " +7(903)-123-45-67" ;
@@ -18,24 +18,24 @@ let regexp = /\d/;
1818alert ( str .match (regexp) ); // 7
1919```
2020
21- Without the flag ` pattern:g ` , the regular expression only looks for the first match, that is the first digit ` pattern:\d ` .
21+ بدون پرچم ` pattern:g ` ، عبارت باقاعده فقط به دنبال اولین تطابق است. که اولین رقم ` pattern:\d ` می باشد .
2222
23- Let's add the ` pattern:g ` flag to find all digits :
23+ بیایید پرچم ` pattern:g ` را اضافه کنیم تا همه ارقام را پیدا کنیم :
2424
2525``` js run
2626let str = " +7(903)-123-45-67" ;
2727
2828let regexp = / \d / g ;
2929
30- alert ( str .match (regexp) ); // array of matches : 7,9,0,3,1,2,3,4,5,6,7
30+ alert ( str .match (regexp) ); // آرایه ای از اعداد : 7,9,0,3,1,2,3,4,5,6,7
3131
32- // let's make the digits-only phone number of them :
32+ // بیایید شماره تلفن را به صورت رقمی بنویسیم :
3333alert ( str .match (regexp).join (' ' ) ); // 79031234567
3434```
3535
36- That was a character class for digits. There are other character classes as well .
36+ این یک کلاس کاراکتر برای ارقام بود. کلاس های کاراکتر های دیگری نیز وجود دارند .
3737
38- Most used are :
38+ بیشترین استفاده ها عبارتند از :
3939
4040` pattern:\d ` ("d" is from "digit")
4141: A digit: a character from ` 0 ` to ` 9 ` .
0 commit comments