|
1 | 1 | সংখ্যা খুঁজার রেগুলার এক্সপ্রেশন: `pattern:-?\d+(\.\d+)?`। যা আমরা পূর্বের টাস্কে করেছিলাম।
|
2 | 2 |
|
3 |
| -অপারেটর হল `pattern:[-+*/]`. হাইফেন `pattern:-` অবশ্যই ব্রাকেটের শুরুতে হতে হবে, কেননা মাঝে হলে এটি দ্বারা ক্যারাক্টারের রেঞ্জ বুঝায়, যেখানে আমরা `-` কে ক্যারাক্টার হিসেবে দেখতে চায়। |
| 3 | +অপারেটর হল `pattern:[-+*/]`. হাইফেন `pattern:-` অবশ্যই ব্রাকেটের শুরুতে হতে হবে, কেননা মাঝে হলে এটি দ্বারা ক্যারাক্টারের রেঞ্জ বুঝায়, এখানে আমরা `-` কে ক্যারাক্টার হিসেবে ব্যবহার করতে চায়। |
4 | 4 |
|
5 |
| -The slash `/` should be escaped inside a JavaScript regexp `pattern:/.../`, we'll do that later. |
| 5 | +স্ল্যাশ `/` অবশ্যই জাভাস্ক্রিপ্টের রেগুলার এক্সপ্রেশনের মাঝে এস্কেপড `pattern:/.../` হয়, এটি আমরা এটি পরে দেখব। |
6 | 6 |
|
7 |
| -We need a number, an operator, and then another number. And optional spaces between them. |
| 7 | +আমাদের খুঁজা লাগবে একটি সংখ্যা অতঃপর একটি গাণিতিক চিহ্ন এবং শেষে আরো একটি সংখ্যা এবং তাদের মাঝের অতিরিক্ত স্পেস। |
8 | 8 |
|
9 |
| -The full regular expression: `pattern:-?\d+(\.\d+)?\s*[-+*/]\s*-?\d+(\.\d+)?`. |
10 | 9 |
|
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+)?`। |
15 | 11 |
|
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+)?` - দ্বিতীয় সংখ্যাটি। |
17 | 16 |
|
18 |
| -In action: |
| 17 | +তাদের প্রত্যেককে রেজাল্ট অ্যারের আলাদা আলাদা উপাদান হিসেবে রাখতে প্যারান্টেসিস দ্বারা গ্রুপ করি: `pattern:(-?\d+(\.\d+)?)\s*([-+*/])\s*(-?\d+(\.\d+)?)`। |
| 18 | + |
| 19 | +যেমন: |
19 | 20 |
|
20 | 21 | ```js run
|
21 | 22 | let regexp = /(-?\d+(\.\d+)?)\s*([-+*\/])\s*(-?\d+(\.\d+)?)/;
|
22 | 23 |
|
23 | 24 | alert( "1.2 + 12".match(regexp) );
|
24 | 25 | ```
|
25 | 26 |
|
26 |
| -The result includes: |
| 27 | +রেজাল্টে: |
27 | 28 |
|
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) |
34 | 35 |
|
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" করি। |
36 | 37 |
|
37 |
| -The full match (the arrays first item) can be removed by shifting the array `result.shift()`. |
| 38 | +সম্পূর্ন অংশটি যা অ্যারের প্রথম ইলিমেন্ট একে আমরা `result.shift()` মেথডের সাহায্যে বাদ দিতে পারি। |
38 | 39 |
|
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+)?`। |
40 | 41 |
|
41 |
| -The final solution: |
| 42 | +সুতরাং সমাধানটি হবে: |
42 | 43 |
|
43 | 44 | ```js run
|
44 | 45 | function parse(expr) {
|
|
0 commit comments