Skip to content

Commit 9bbbe1c

Browse files
committed
done task-4
1 parent 4ecd603 commit 9bbbe1c

File tree

1 file changed

+22
-21
lines changed
  • 9-regular-expressions/11-regexp-groups/04-parse-expression

1 file changed

+22
-21
lines changed

Diff for: 9-regular-expressions/11-regexp-groups/04-parse-expression/solution.md

+22-21
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,45 @@
11
সংখ্যা খুঁজার রেগুলার এক্সপ্রেশন: `pattern:-?\d+(\.\d+)?`। যা আমরা পূর্বের টাস্কে করেছিলাম।
22

3-
অপারেটর হল `pattern:[-+*/]`. হাইফেন `pattern:-` অবশ্যই ব্রাকেটের শুরুতে হতে হবে, কেননা মাঝে হলে এটি দ্বারা ক্যারাক্টারের রেঞ্জ বুঝায়, যেখানে আমরা `-` কে ক্যারাক্টার হিসেবে দেখতে চায়।
3+
অপারেটর হল `pattern:[-+*/]`. হাইফেন `pattern:-` অবশ্যই ব্রাকেটের শুরুতে হতে হবে, কেননা মাঝে হলে এটি দ্বারা ক্যারাক্টারের রেঞ্জ বুঝায়, এখানে আমরা `-` কে ক্যারাক্টার হিসেবে ব্যবহার করতে চায়।
44

5-
The slash `/` should be escaped inside a JavaScript regexp `pattern:/.../`, we'll do that later.
5+
স্ল্যাশ `/` অবশ্যই জাভাস্ক্রিপ্টের রেগুলার এক্সপ্রেশনের মাঝে এস্কেপড `pattern:/.../` হয়, এটি আমরা এটি পরে দেখব।
66

7-
We need a number, an operator, and then another number. And optional spaces between them.
7+
আমাদের খুঁজা লাগবে একটি সংখ্যা অতঃপর একটি গাণিতিক চিহ্ন এবং শেষে আরো একটি সংখ্যা এবং তাদের মাঝের অতিরিক্ত স্পেস।
88

9-
The full regular expression: `pattern:-?\d+(\.\d+)?\s*[-+*/]\s*-?\d+(\.\d+)?`.
109

11-
It has 3 parts, with `pattern:\s*` between them:
12-
1. `pattern:-?\d+(\.\d+)?` - the first number,
13-
1. `pattern:[-+*/]` - the operator,
14-
1. `pattern:-?\d+(\.\d+)?` - the second number.
10+
সুতরাং রেগুলার এক্সপ্রেশনটি হবে: `pattern:-?\d+(\.\d+)?\s*[-+*/]\s*-?\d+(\.\d+)?`
1511

16-
To make each of these parts a separate element of the result array, let's enclose them in parentheses: `pattern:(-?\d+(\.\d+)?)\s*([-+*/])\s*(-?\d+(\.\d+)?)`.
12+
এর ৩টি অংশ আছে, সাথে এটিও `pattern:\s*`:
13+
১. `pattern:-?\d+(\.\d+)?` - প্রথম সংখ্যাটি।
14+
২. `pattern:[-+*/]` - গাণিতিক চিহ্নটি।
15+
৩. `pattern:-?\d+(\.\d+)?` - দ্বিতীয় সংখ্যাটি।
1716

18-
In action:
17+
তাদের প্রত্যেককে রেজাল্ট অ্যারের আলাদা আলাদা উপাদান হিসেবে রাখতে প্যারান্টেসিস দ্বারা গ্রুপ করি: `pattern:(-?\d+(\.\d+)?)\s*([-+*/])\s*(-?\d+(\.\d+)?)`
18+
19+
যেমন:
1920

2021
```js run
2122
let regexp = /(-?\d+(\.\d+)?)\s*([-+*\/])\s*(-?\d+(\.\d+)?)/;
2223

2324
alert( "1.2 + 12".match(regexp) );
2425
```
2526

26-
The result includes:
27+
রেজাল্টে:
2728

28-
- `result[0] == "1.2 + 12"` (full match)
29-
- `result[1] == "1.2"` (first group `(-?\d+(\.\d+)?)` -- the first number, including the decimal part)
30-
- `result[2] == ".2"` (second group`(\.\d+)?` -- the first decimal part)
31-
- `result[3] == "+"` (third group `([-+*\/])` -- the operator)
32-
- `result[4] == "12"` (forth group `(-?\d+(\.\d+)?)` -- the second number)
33-
- `result[5] == undefined` (fifth group `(\.\d+)?` -- the last decimal part is absent, so it's undefined)
29+
- `result[0] == "1.2 + 12"` (সম্পূর্ন এক্সপ্রেশনটি)
30+
- `result[1] == "1.2"` (প্রথম গ্রুপ `(-?\d+(\.\d+)?)` -- প্রথম সংখ্যাটি, দশমিক অংশটিসহ)
31+
- `result[2] == ".2"` (দ্বিতীয় গ্রুপ`(\.\d+)?` -- প্রথম দশমিক অংশটি)
32+
- `result[3] == "+"` (তৃতীয় গ্রুপ `([-+*\/])` -- গাণিতিক চিহ্নটি)
33+
- `result[4] == "12"` (চতুর্থ গ্রুপ `(-?\d+(\.\d+)?)` -- দ্বিতীয় সংখ্যাটি)
34+
- `result[5] == undefined` (পঞ্চম গ্রুপ `(\.\d+)?` -- দ্বিতীয় দশমিক অংশটি অনুপস্থিত, সুতরাং এটি undefined)
3435

35-
We only want the numbers and the operator, without the full match or the decimal parts, so let's "clean" the result a bit.
36+
আমরা শুধু সংখ্যাগুলো এবং গাণিতিক চিহ্নটি চায়, সম্পূর্ন অংশটি বা দশমিক অংশটি চায় না, সুতরাং আমাদের রেজাল্টকে আরো কিছুটা "clean" করি।
3637

37-
The full match (the arrays first item) can be removed by shifting the array `result.shift()`.
38+
সম্পূর্ন অংশটি যা অ্যারের প্রথম ইলিমেন্ট একে আমরা `result.shift()` মেথডের সাহায্যে বাদ দিতে পারি।
3839

39-
Groups that contain decimal parts (number 2 and 4) `pattern:(.\d+)` can be excluded by adding `pattern:?:` to the beginning: `pattern:(?:\.\d+)?`.
40+
যে গ্রুপগুলোতে দশমিক অংশ থাকে (২ এবং ৪ আইটেম) এই অংশের `pattern:(.\d+)` শুরুতে `pattern:?:` যোগ করে তাদের বাদ দিতে পারি: `pattern:(?:\.\d+)?`
4041

41-
The final solution:
42+
সুতরাং সমাধানটি হবে:
4243

4344
```js run
4445
function parse(expr) {

0 commit comments

Comments
 (0)