Skip to content

Commit 9d7c55f

Browse files
committed
translate sticky regex into arabic
1 parent ac5dd28 commit 9d7c55f

1 file changed

Lines changed: 28 additions & 28 deletions

File tree

9-regular-expressions/16-regexp-sticky/article.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11

2-
# Sticky flag "y", searching at position
2+
# علم ثابت "y" ، البحث في الموضع
33

4-
The flag `pattern:y` allows to perform the search at the given position in the source string.
4+
تسمح العلامة `pattern: y` بالبحث في الموضع المحدد في السلسلة المصدر.
55

6-
To grasp the use case of `pattern:y` flag, and see how great it is, let's explore a practical use case.
6+
لفهم حالة استخدام علامة "pattern: y" ، ومعرفة مدى روعتها ، دعنا نستكشف حالة استخدام عملية.
77

8-
One of common tasks for regexps is "lexical analysis": we get a text, e.g. in a programming language, and analyze it for structural elements.
8+
إحدى المهام الشائعة لـ regexps هي "التحليل المعجمي": نحصل على نص ، على سبيل المثال في لغة البرمجة ، وتحليلها للعناصر الهيكلية.
99

10-
For instance, HTML has tags and attributes, JavaScript code has functions, variables, and so on.
10+
على سبيل المثال ، يحتوي HTML على علامات وسمات ، وشفرة JavaScript لها وظائف ، ومتغيرات ، وما إلى ذلك.
1111

12-
Writing lexical analyzers is a special area, with its own tools and algorithms, so we don't go deep in there, but there's a common task: to read something at the given position.
12+
تعد كتابة المحللات المعجمية مجالًا خاصًا ، مع أدواته وخوارزمياته الخاصة ، لذلك لا نتعمق في ذلك ، ولكن هناك مهمة مشتركة: قراءة شيء ما في الموضع المحدد.
1313

14-
E.g. we have a code string `subject:let varName = "value"`, and we need to read the variable name from it, that starts at position `4`.
14+
على سبيل المثال لدينا سلسلة التعليمات البرمجية `subject: let varName =" value "` ، ونحتاج إلى قراءة اسم المتغير منه ، الذي يبدأ في الموضع `4`.
1515

16-
We'll look for variable name using regexp `pattern:\w+`. Actually, JavaScript variable names need a bit more complex regexp for accurate matching, but here it doesn't matter.
16+
سنبحث عن اسم متغير باستخدام نمط regexp `: \ w +`. في الواقع ، تحتاج أسماء متغيرات جافا سكريبت إلى regexp أكثر تعقيدًا قليلاً لمطابقة دقيقة ، ولكن هنا لا يهم.
1717

18-
A call to `str.match(/\w+/)` will find only the first word in the line. Or all words with the flag `pattern:g`. But we need only one word at position `4`.
18+
استدعاء `str.match (/ \ w + /)` سيجد الكلمة الأولى فقط في السطر. أو جميع الكلمات التي تحمل علامة `pattern: g`. ولكننا نحتاج إلى كلمة واحدة فقط في الموضع `4`.
1919

20-
To search from the given position, we can use method `regexp.exec(str)`.
20+
للبحث من الموضع المحدد ، يمكننا استخدام الطريقة `regexp.exec (str)`.
2121

22-
If the `regexp` doesn't have flags `pattern:g` or `pattern:y`, then this method looks for the first match in the string `str`, exactly like `str.match(regexp)`. Such simple no-flags case doesn't interest us here.
22+
إذا كان "regexp" لا يحتوي على علامات `pattern: g` أو` pattern: y` ، فإن هذه الطريقة تبحث عن المطابقة الأولى في السلسلة `str` ، تمامًا مثل` str.match (regexp) `. لا تثير اهتمامنا مثل هذه الحالة البسيطة التي لا توجد أعلام فيها.
2323

24-
If there's flag `pattern:g`, then it performs the search in the string `str`, starting from position stored in its `regexp.lastIndex` property. And, if it finds a match, then sets `regexp.lastIndex` to the index immediately after the match.
24+
إذا كان هناك علامة `pattern: g` ، فسيتم البحث في السلسلة` str` ، بدءًا من الموضع المخزن في خاصية `regexp.lastIndex`. وإذا وجد تطابقًا ، فعيّن "regexp.lastIndex" إلى الفهرس بعد المباراة مباشرة.
2525

26-
When a regexp is created, its `lastIndex` is `0`.
26+
عند إنشاء regexp ، يكون "lastIndex" هو "0".
2727

28-
So, successive calls to `regexp.exec(str)` return matches one after another.
28+
لذلك ، المكالمات المتتالية لعودة `regexp.exec (str)` تتطابق واحدة تلو الأخرى.
2929

30-
An example (with flag `pattern:g`):
30+
مثال (بعلامة `pattern: g`):
3131

3232
```js run
3333
let str = 'let varName';
@@ -48,9 +48,9 @@ alert(word3); // null (no more matches)
4848
alert(regexp.lastIndex); // 0 (resets at search end)
4949
```
5050

51-
Every match is returned as an array with groups and additional properties.
51+
يتم إرجاع كل مباراة كمصفوفة بمجموعات وخصائص إضافية.
5252

53-
We can get all matches in the loop:
53+
يمكننا الحصول على جميع المباريات في الحلقة:
5454

5555
```js run
5656
let str = 'let varName';
@@ -65,11 +65,11 @@ while (result = regexp.exec(str)) {
6565
}
6666
```
6767

68-
Such use of `regexp.exec` is an alternative to method `str.matchAll`.
68+
يعد استخدام `regexp.exec` بديلاً للطريقة` str.matchAll`.
6969

70-
Unlike other methods, we can set our own `lastIndex`, to start the search from the given position.
70+
على عكس الطرق الأخرى ، يمكننا تعيين "lastIndex" الخاص بنا لبدء البحث من الموضع المحدد.
7171

72-
For instance, let's find a word, starting from position `4`:
72+
على سبيل المثال ، دعنا نجد كلمة ، بدءًا من الموضع `4`:
7373

7474
```js run
7575
let str = 'let varName = "value"';
@@ -84,9 +84,9 @@ let word = regexp.exec(str);
8484
alert(word); // varName
8585
```
8686

87-
We performed a search of `pattern:\w+`, starting from position `regexp.lastIndex = 4`.
87+
أجرينا بحثًا عن `النمط: \ w +` ، بدءًا من الموضع `regexp.lastIndex = 4`.
8888

89-
Please note: the search starts at position `lastIndex` and then goes further. If there's no word at position `lastIndex`, but it's somewhere after it, then it will be found:
89+
يرجى ملاحظة: يبدأ البحث في الموضع `lastIndex` ثم يذهب إلى أبعد من ذلك. إذا لم يكن هناك كلمة في الموضع `lastIndex` ، لكنها موجودة في مكان ما بعدها ، فسيتم العثور عليها:
9090

9191
```js run
9292
let str = 'let varName = "value"';
@@ -102,11 +102,11 @@ alert(word[0]); // varName
102102
alert(word.index); // 4
103103
```
104104

105-
...So, with flag `pattern:g` property `lastIndex` sets the starting position for the search.
105+
...So ، مع وضع علامة `pattern: g` خاصية` lastIndex` تحدد موضع البداية للبحث.
106106

107-
**Flag `pattern:y` makes `regexp.exec` to look exactly at position `lastIndex`, not before, not after it.**
107+
** وضع علامة على "النمط: y" يجعل "regexp.exec" ينظر بالضبط إلى الموضع "lastIndex" ، ليس قبله وليس بعده. **
108108

109-
Here's the same search with flag `pattern:y`:
109+
هذا هو نفس البحث مع العلم `pattern: y`:
110110

111111
```js run
112112
let str = 'let varName = "value"';
@@ -120,8 +120,8 @@ regexp.lastIndex = 4;
120120
alert( regexp.exec(str) ); // varName (word at position 4)
121121
```
122122

123-
As we can see, regexp `pattern:/\w+/y` doesn't match at position `3` (unlike the flag `pattern:g`), but matches at position `4`.
123+
كما نرى ، لا يتطابق regexp `pattern: / \ w + / y` في الموضع` 3` (على عكس العلم `pattern: g`) ، ولكنه يتطابق في الموضع` 4`.
124124

125-
Imagine, we have a long text, and there are no matches in it, at all. Then searching with flag `pattern:g` will go till the end of the text, and this will take significantly more time than the search with flag `pattern:y`.
125+
تخيل ، لدينا نص طويل ، ولا يوجد تطابق على الإطلاق. ثم البحث باستخدام العلامة `نقش: g` سيستمر حتى نهاية النص ، وسيستغرق هذا وقتًا أكثر بكثير من البحث باستخدام العلم` نقش: ص`.
126126

127-
In such tasks like lexical analysis, there are usually many searches at an exact position. Using flag `pattern:y` is the key for a good performance.
127+
في مثل هذه المهام مثل التحليل المعجمي ، عادة ما تكون هناك العديد من عمليات البحث في موضع محدد. إن استخدام العلم `pattern: y` هو مفتاح الأداء الجيد.

0 commit comments

Comments
 (0)