Skip to content

Commit 7cfafb2

Browse files
authored
Merge pull request #199 from msisaifu/greedy-lazy-mode
Greedy and lazy quantifiers
2 parents 8d7af65 + 5b598d9 commit 7cfafb2

File tree

7 files changed

+127
-126
lines changed

7 files changed

+127
-126
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
The result is: `match:123 4`.
2+
ফলাফলটি হল: `match:123 4`
33

4-
First the lazy `pattern:\d+?` tries to take as little digits as it can, but it has to reach the space, so it takes `match:123`.
4+
প্রথমে লেজি মোডে এই প্যাটার্নটি `pattern:\d+?` চেষ্টা করে যত কম সম্ভব অঙ্ক নেয়ার, কিন্তু প্যাটার্নের পরবর্তী স্পেস এর জন্য এটি স্পেস পর্যন্ত মেলে, সুতরাং এটি `match:123` এর সাথে মেলে।
55

6-
Then the second `\d+?` takes only one digit, because that's enough.
6+
অতঃপর পরবর্তী `\d+?` শুধু একটি অঙ্ক নেই, কেননা এরপর আর কোন প্যাটার্ন নেই।

Diff for: 9-regular-expressions/10-regexp-greedy-and-lazy/1-lazy-greedy/task.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# A match for /d+? d+?/
1+
# /d+? d+?/ এর মিল
22

3-
What's the match here?
3+
এখানে অনুসন্ধানে কি পাওয়া যাবে?
44

55
```js
66
"123 456".match(/\d+? \d+?/g) ); // ?

Diff for: 9-regular-expressions/10-regexp-greedy-and-lazy/3-find-html-comments/solution.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
We need to find the beginning of the comment `match:<!--`, then everything till the end of `match:-->`.
1+
আমাদের প্রথমে খুঁজা লাগবে কমেন্ট এর শুরুর `match:<!--` অংশ, এরপর কমেন্টের শেষ `match:-->` অংশ।
22

3-
An acceptable variant is `pattern:<!--.*?-->` -- the lazy quantifier makes the dot stop right before `match:-->`. We also need to add flag `pattern:s` for the dot to include newlines.
3+
সুতরাং প্যাটার্নটি হবে `pattern:<!--.*?-->` -- লেজি কোয়ান্টিফায়ারের ডটের জন্য এটি `match:-->` এর পূর্ব পর্যন্ত মেলে। আমাদের এই ফ্ল্যাগটি `pattern:s` দিতে হবে যেন ডট দ্বারা নিউলাইন ক্যারাক্টারকেও নির্দেশ করে।
44

5-
Otherwise multiline comments won't be found:
5+
অন্যথায় একের অধিক লাইনের কমেন্টগুলো অনুসন্ধানে আসবে না:
66

77
```js run
88
let regexp = /<!--.*?-->/gs;

Diff for: 9-regular-expressions/10-regexp-greedy-and-lazy/3-find-html-comments/task.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Find HTML comments
1+
# এইচটিএমএল কমেন্ট অনুসন্ধান
22

3-
Find all HTML comments in the text:
3+
নিচের টেক্সট হতে সকল এইচটিএমএল কমেন্ট খুঁজার একটি প্যাটার্ন লিখুন:
44

55
```js
6-
let regexp = /your regexp/g;
6+
let regexp = /আপনার প্যাটার্ন/g;
77

88
let str = `... <!-- My -- comment
9-
test --> .. <!----> ..
9+
test --> .. <!----> ..
1010
`;
1111

1212
alert( str.match(regexp) ); // '<!-- My -- comment \n test -->', '<!---->'

Diff for: 9-regular-expressions/10-regexp-greedy-and-lazy/4-find-html-tags-greedy-lazy/solution.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
The solution is `pattern:<[^<>]+>`.
2+
সমাধানটি হল `pattern:<[^<>]+>`
33

44
```js run
55
let regexp = /<[^<>]+>/g;
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
# Find HTML tags
1+
# এইচটিএমএল ট্যাগের অনুসন্ধান
22

3-
Create a regular expression to find all (opening and closing) HTML tags with their attributes.
3+
একটি প্যাটার্ন লিখুন যেন সকল এইচটিএমএল ট্যাগগুলো(অ্যাট্রিবিউটসহ) খুঁজে পায়.
44

5-
An example of use:
5+
উদাহরণস্বরূপ:
66

77
```js run
8-
let regexp = /your regexp/g;
8+
let regexp = /আপনার প্যাটার্ন/g;
99

1010
let str = '<> <a href="/"> <input type="radio" checked> <b>';
1111

1212
alert( str.match(regexp) ); // '<a href="/">', '<input type="radio" checked>', '<b>'
1313
```
1414

15-
Here we assume that tag attributes may not contain `<` and `>` (inside squotes too), that simplifies things a bit.
15+
এখানে কিছুটা সহজের জন্য আমরা ধরে নিয়েছি অ্যাট্রিবিউটের মাঝে এই দুটি বন্ধনী `<` এবং `>` থাকবে না।

0 commit comments

Comments
 (0)