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
That was a character class for digits. There are other character classes as well.
35
+
وهذا كان فئة الحرف للأرقام. هناك فئات الاحرف الاخري كذلك.
37
36
38
-
Most used are:
37
+
الأكثر أستخداماً:
39
38
40
-
`pattern:\d` ("d" is from "digit")
41
-
: A digit: a character from `0`to`9`.
39
+
`pattern:\d` ( الحرف "d" جاء من كلمة "digit")
40
+
: الرقم: يكون من `0`الي`9`.
42
41
43
-
`pattern:\s` ("s" is from "space")
44
-
: A space symbol: includes spaces, tabs `\t`, newlines `\n`and few other rare characters, such as `\v`, `\f`and`\r`.
42
+
`pattern:\s` ( الحرف "s" جاء من كلمة "space")
43
+
: رمز المسافة: يحتوي علي مسافات او مسافات طويلة `\t` او أسطر جديده `\n`وعدد قليل من الاحرف النادرة الاخري, مثل `\v` و `\f`و`\r`.
45
44
46
-
`pattern:\w` ("w" is from "word")
47
-
: A "wordly" character: either a letter of Latin alphabet or a digit or an underscore `_`. Non-Latin letters (like cyrillic or hindi) do not belong to`pattern:\w`.
45
+
`pattern:\w` ( الحرف "w" جاء من كلمة "word")
46
+
: الحرف هذا: إما حرف الأبجدية اللاتينية أو رقم أو تسطير أسفل السطر `_`. لا تنتمي الأحرف غير اللاتينية (مثل السيريلية أو الهندية)`pattern:\w`.
48
47
49
-
For instance, `pattern:\d\s\w`means a "digit" followed by a "space character" followed by a "wordly character", such as`match:1 a`.
48
+
علي سبيل المثال, `pattern:\d\s\w`الرمز هذا يعني رقم يأتي بعده مسافة ثم يُتبع بحرف, مثل`match:1 a`.
50
49
51
-
**A regexp may contain both regular symbols and character classes.**
50
+
**قد يحتوي التعبير المنتظم على كل من الرموز المنتظمة وفئات الاحرف.**
52
51
53
-
For instance, `pattern:CSS\d`matches a string`match:CSS`with a digit after it:
52
+
علي سبيل المثال, `pattern:CSS\d`ينتج عنه نص`match:CSS`مع رقم يأتي بعده:
54
53
55
54
```js run
56
55
let str ="Is there CSS4?";
@@ -59,145 +58,145 @@ let regexp = /CSS\d/
59
58
alert( str.match(regexp) ); // CSS4
60
59
```
61
60
62
-
Also we can use many character classes:
61
+
أيضاً نستطيع أستخدام الكثير من فئات الأحرف:
63
62
64
63
```js run
65
64
alert( "I love HTML5!".match(/\s\w\w\w\w\d/) ); // ' HTML5'
66
65
```
67
66
68
-
The match (each regexp character class has the corresponding result character):
67
+
الناتج (كل فئة حرف تقابلها الناتج الخاص بها):
69
68
70
69

71
70
72
-
## Inverse classes
71
+
## الفئات العكسية
73
72
74
-
For every character class there exists an "inverse class", denoted with the same letter, but uppercased.
73
+
يوجد لكل فئة أحرف "فئة معكوسة" ، يُشار إليها بالحرف نفسه ، ولكن بالأحرف الكبيرة.
75
74
76
-
The "inverse" means that it matches all other characters, for instance:
75
+
يعني "معكوس" أنه يطابق جميع الأحرف الأخرى ، على سبيل المثال:
77
76
78
77
`pattern:\D`
79
-
: Non-digit: any character except `pattern:\d`, for instance a letter.
78
+
: غير رقمي: أي حرف ما عدا `pattern:\d`, علي سبيل المثال حرف نصي.
80
79
81
80
`pattern:\S`
82
-
: Non-space: any character except `pattern:\s`, for instance a letter.
81
+
: بدون مسافة: أي حرف ما عدا `pattern:\s`, علي سبيل المثال حرف نصي.
83
82
84
83
`pattern:\W`
85
-
: Non-wordly character: anything but `pattern:\w`, e.g a non-latin letter or a space.
84
+
: حرف غير نصي: أي شئ لكن `pattern:\w`, علي سبيل المثال حرف غير لاتيني او مسافة.
86
85
87
-
In the beginning of the chapter we saw how to make a number-only phone number from a string like `subject:+7(903)-123-45-67`: find all digits and join them.
86
+
في بداية الفصل رأينا كيفية صنع رقم هاتف لرقم فقط من النص مثل`subject:+7(903)-123-45-67`: أيجاد كل الارقام وتم جمعهم.
The pattern `pattern:[\s\S]` literally says: "a space character OR not a space character". In other words, "anything". We could use another pair of complementary classes, such as `pattern:[\d\D]`, that doesn't matter. Or even the `pattern:[^]` -- as it means match any character except nothing.
155
+
الرمز `pattern:[\s\S]` يقول: "حرف مسافة او ليس حرف مسافة". وبعبارة أخرى ، "أي شيء". يمكننا أستخدام زوج أخر من الفئات التكميلية, مثل `pattern:[\d\D]`, لا يهم أو حتي `pattern:[^]` -- لأنه يعني مطابقة أي حرف باستثناء أي شيء.
157
156
158
-
Also we can use this trick if we want both kind of "dots" in the same pattern: the actual dot `pattern:.` behaving the regular way ("not including a newline"), and also a way to match "any character" with `pattern:[\s\S]` or alike.
157
+
كما يمكننا استخدام هذه الخدعة إذا أردنا نوعي "النقاط" في نفس النمط: النقطة الفعلية "النقط" في نفس الرمز: النقطة الفعلية `pattern:.` يشتغل بالطريقة المنتظمة ("لا يحتوي علي سطر جديد"), وأيضاً طريقة أخري للحصول علي "أي حرف" مع الرمز `pattern:[\s\S]` او علي حد سواء.
159
158
````
160
159
161
-
````warn header="Pay attention to spaces"
162
-
Usually we pay little attention to spaces. For us strings `subject:1-5` and `subject:1 - 5` are nearly identical.
160
+
````warn header="أنتبه للمسافات"
161
+
عادة نولي القليل من الاهتمام للمساحات. للنصوص `subject:1-5` و `subject:1 - 5` متطابة تقريباً.
163
162
164
-
But if a regexp doesn't take spaces into account, it may fail to work.
163
+
ولكن أذا كان التعبير المنتظم لا يحسب مسافات, قد تفشل في العمل.
165
164
166
-
Let's try to find digits separated by a hyphen:
165
+
فلنحاول أيجاد الأرقام مفصوله بواصلة:
167
166
168
167
```js run
169
-
alert( "1 - 5".match(/\d-\d/) ); // null, no match!
168
+
alert( "1 - 5".match(/\d-\d/) ); // null, لا ناتج!
170
169
```
171
170
172
-
Let's fix it adding spaces into the regexp `pattern:\d - \d`:
171
+
دعنا نصلحه بإضافة مسافات إلى التعبير المنتظم `pattern:\d - \d`:
173
172
174
173
```js run
175
-
alert( "1 - 5".match(/\d - \d/) ); // 1 - 5, now it works
174
+
alert( "1 - 5".match(/\d - \d/) ); // 1 - 5, الان أنها تعمل
176
175
// or we can use \s class:
177
-
alert( "1 - 5".match(/\d\s-\s\d/) ); // 1 - 5, also works
176
+
alert( "1 - 5".match(/\d\s-\s\d/) ); // 1 - 5, أيضاً تعمل
178
177
```
179
178
180
-
**A space is a character. Equal in importance with any other character.**
179
+
**المسافة تعتبر حرف. تساوي في الاهمية مع أي حرف أخر.**
181
180
182
-
We can't add or remove spaces from a regular expression and expect to work the same.
181
+
لا يمكننا إضافة مسافات أو إزالتها من التعبير المنتظم ونتوقع أن تعمل بالطريقة نفسها.
183
182
184
-
In other words, in a regular expression all characters matter, spaces too.
183
+
بمعني أخر, في التعبير المنتظم كل الحروف لها أهمية, والمسافات أيضاً.
185
184
````
186
185
187
-
## Summary
186
+
## الملخص
188
187
189
-
There exist following character classes:
188
+
توجد فئات الأحرف التالية:
190
189
191
-
-`pattern:\d` -- digits.
192
-
-`pattern:\D` -- non-digits.
193
-
-`pattern:\s` -- space symbols, tabs, newlines.
194
-
-`pattern:\S` -- all but`pattern:\s`.
195
-
-`pattern:\w` -- Latin letters, digits, underscore`'_'`.
196
-
-`pattern:\W` -- all but`pattern:\w`.
197
-
-`pattern:.` -- any character if with the regexp `'s'` flag, otherwise any except a newline`\n`.
190
+
-`pattern:\d` -- الارقام.
191
+
-`pattern:\D` -- غير الارقام.
192
+
-`pattern:\s` -- مسافات و مسافات طويلة وسطر جديد.
193
+
-`pattern:\S` -- أي شئ ما عدا`pattern:\s`.
194
+
-`pattern:\w` -- الحروف اللاتينية و الارقام و التطسير`'_'`.
195
+
-`pattern:\W` -- الكل ما عدا`pattern:\w`.
196
+
-`pattern:.` -- أي حرف أذا كان مع التعبير المنتظم العلم `'s'`, غير ذلك يكون أي شئ ما عدا السطر الجديد`\n`.
198
197
199
-
...But that's not all!
198
+
...ولكن هذا ليس كل شيء!
200
199
201
-
Unicode encoding, used by JavaScript for strings, provides many properties for characters, like: which language the letter belongs to (if it's a letter) it is it a punctuation sign, etc.
200
+
يوفر ترميز Unicode ، الذي تستخدمه JavaScript للسلاسل ، العديد من الخصائص للأحرف ، مثل: اللغة التي ينتمي إليها الحرف (إذا كان حرفًا) فهو علامة ترقيم ، إلخ.
202
201
203
-
We can search by these properties as well. That requires flag`pattern:u`, covered in the next article.
202
+
يمكننا البحث بهذه الخصائص أيضًا. هذا يتطلب العلم`pattern:u`, تم تغطيته في المقال التالي.
0 commit comments