Skip to content

Commit 49a3f6a

Browse files
authored
Merge pull request #109 from msisaifu/capturing-groups
Capturing groups
2 parents b710e4a + 85b8d28 commit 49a3f6a

File tree

9 files changed

+178
-178
lines changed

9 files changed

+178
-178
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
A two-digit hex number is `pattern:[0-9a-f]{2}` (assuming the flag `pattern:i` is set).
1+
একটি দুই অঙ্কবিশিষ্ট হেক্সাডেসিমেল নাম্বারের প্যাটার্ন হল `pattern:[0-9a-f]{2}` (ধরে নিই, `pattern:i` ফ্ল্যাগ সেট আছে)।
22

3-
We need that number `NN`, and then `:NN` repeated 5 times (more numbers);
3+
সুতরাং আমাদের এই নাম্বারটি `NN` লাগবে, এবং এটির `:NN` ৫ বার পুনরাবৃত্তি হবে;
44

5-
The regexp is: `pattern:[0-9a-f]{2}(:[0-9a-f]{2}){5}`
5+
সুতরাং রেগুলার এক্সপ্রেশনটি হবে: `pattern:[0-9a-f]{2}(:[0-9a-f]{2}){5}`
66

7-
Now let's show that the match should capture all the text: start at the beginning and end at the end. That's done by wrapping the pattern in `pattern:^...$`.
7+
এখন চলুন ম্যাচটি শুরু থেকে শেষ পর্যন্ত সকল পুরো লাইনটি পাঠ করার উপযোগী করি। এজন্য সম্পূর্ন প্যাটার্নটি `pattern:^...$` এর মধ্যে লিখি।
88

9-
Finally:
9+
শেষ পর্যন্ত:
1010

1111
```js run
1212
let regexp = /^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}$/i;
1313

14-
alert( regexp.test('01:32:54:67:89:AB') ); // true
14+
alert( regexp.test('01:32:54:67:89:AB') ); // সত্য
1515

16-
alert( regexp.test('0132546789AB') ); // false (no colons)
16+
alert( regexp.test('0132546789AB') ); // মিথ্যা (কোলন নেয়)
1717

18-
alert( regexp.test('01:32:54:67:89') ); // false (5 numbers, need 6)
18+
alert( regexp.test('01:32:54:67:89') ); // মিথ্যা (৫টি নাম্বার, অবশ্যই ৬টি হতে হবে)
1919

20-
alert( regexp.test('01:32:54:67:89:ZZ') ) // false (ZZ in the end)
20+
alert( regexp.test('01:32:54:67:89:ZZ') ) // মিথ্যা (শেষে ZZ)
2121
```
+10-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
# Check MAC-address
1+
# MAC-address যাচাই
22

3-
[MAC-address](https://en.wikipedia.org/wiki/MAC_address) of a network interface consists of 6 two-digit hex numbers separated by a colon.
3+
[MAC-address](https://en.wikipedia.org/wiki/MAC_address) হল নেটওয়ার্ক ইন্টারফেসের ৬ টি দুই অঙ্কবিশিষ্ট একটি হেক্সাডেসিমেল নাম্বার যা কোলন দ্বারা পৃথক থাকে।
44

5-
For instance: `subject:'01:32:54:67:89:AB'`.
5+
যেমন: `subject:'01:32:54:67:89:AB'`
66

7-
Write a regexp that checks whether a string is MAC-address.
7+
MAC-address যাচাইয়ের জন্য একটি রেগুলার এক্সপ্রেশন লিখুন।
88

9-
Usage:
9+
উদাহরণস্বরুপ:
1010
```js
11-
let regexp = /your regexp/;
11+
let regexp = /আপনার প্যাটার্ন লিখুন/;
1212

13-
alert( regexp.test('01:32:54:67:89:AB') ); // true
13+
alert( regexp.test('01:32:54:67:89:AB') ); // সত্য
1414

15-
alert( regexp.test('0132546789AB') ); // false (no colons)
15+
alert( regexp.test('0132546789AB') ); // মিথ্যা (কোলন নেয়)
1616

17-
alert( regexp.test('01:32:54:67:89') ); // false (5 numbers, must be 6)
17+
alert( regexp.test('01:32:54:67:89') ); // মিথ্যা (৫টি নাম্বার, অবশ্যই ৬টি হতে হবে)
1818

19-
alert( regexp.test('01:32:54:67:89:ZZ') ) // false (ZZ ad the end)
19+
alert( regexp.test('01:32:54:67:89:ZZ') ) // মিথ্যা (শেষে ZZ)
2020
```

Diff for: 9-regular-expressions/11-regexp-groups/02-find-webcolor-3-or-6/solution.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
A regexp to search 3-digit color `#abc`: `pattern:/#[a-f0-9]{3}/i`.
1+
৩ অঙ্কবিশিষ্ট সংখ্যা খুঁজার রেগুলার এক্সপ্রেশন হল `#abc`: `pattern:/#[a-f0-9]{3}/i`
22

3-
We can add exactly 3 more optional hex digits. We don't need more or less. The color has either 3 or 6 digits.
3+
এরপর আমরা শুধুমাত্র আরো ৩অঙ্কবিশিষ্ট অপশনাল হেক্সাডেসিমেল নাম্বার খুঁজার প্যাটার্ন লিখব, আমাদের এর বেশি বা কমের জন্য লাগবে না। সুতরাং কালারটি হবে ৩ বা ৬ অঙ্কের।
44

5-
Let's use the quantifier `pattern:{1,2}` for that: we'll have `pattern:/#([a-f0-9]{3}){1,2}/i`.
5+
চলুন এই জন্য এই কোয়ান্টিফায়ারটি `pattern:{1,2}` ব্যবহার করি: আমাদের প্যাটার্নটি হবে `pattern:/#([a-f0-9]{3}){1,2}/i`
66

7-
Here the pattern `pattern:[a-f0-9]{3}` is enclosed in parentheses to apply the quantifier `pattern:{1,2}`.
7+
এখানে আমরা এই প্যাটার্নটি `pattern:[a-f0-9]{3}` প্যারান্টেসিসের মধ্যে লিখব, যাতে এই কোয়ান্টিফায়ারটি `pattern:{1,2}` ব্যবহার করা যায়।
88

9-
In action:
9+
এখানে দেখুন:
1010

1111
```js run
1212
let regexp = /#([a-f0-9]{3}){1,2}/gi;
@@ -16,7 +16,7 @@ let str = "color: #3f3; background-color: #AA00ef; and: #abcd";
1616
alert( str.match(regexp) ); // #3f3 #AA00ef #abc
1717
```
1818

19-
There's a minor problem here: the pattern found `match:#abc` in `subject:#abcd`. To prevent that we can add `pattern:\b` to the end:
19+
তবে এখানে একটি ছোট্ট সমস্যা আছে `match:#abc` এই স্ট্রিংয়ের জন্যও কাজ করবে `subject:#abcd`, যা সঠিক নয়। এজন্য আমাদের শেষে `pattern:\b` ব্যবহার করা লাগবে:
2020

2121
```js run
2222
let regexp = /#([a-f0-9]{3}){1,2}\b/gi;
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# Find color in the format #abc or #abcdef
1+
# এই কালার ফরম্যাটগুলো খুঁজুন #abc বা #abcdef
22

3-
Write a RegExp that matches colors in the format `#abc` or `#abcdef`. That is: `#` followed by 3 or 6 hexadecimal digits.
3+
একটি রেগুলার এক্সপ্রেশন লিখুন যা এই দুটি কালার ফরম্যাটের সাথে ম্যাচ করবে `#abc` বা `#abcdef`। এটি হবে: `#` দ্বারা ৩ বা ৬ অঙ্কের হেক্সাডেসিমেল নাম্বার।
44

5-
Usage example:
5+
উদাহরণস্বরুপ:
66
```js
7-
let regexp = /your regexp/g;
7+
let regexp = /আপনার প্যাটার্ন লিখুন/g;
88

99
let str = "color: #3f3; background-color: #AA00ef; and: #abcd";
1010

1111
alert( str.match(regexp) ); // #3f3 #AA00ef
1212
```
1313

14-
P.S. This should be exactly 3 or 6 hex digits. Values with 4 digits, such as `#abcd`, should not match.
14+
বি.দ্র. এটি অবশ্যই ৩ বা ৬ অঙ্কের হেক্সাডেসিমেল নাম্বার হতে হবে। যেমন, ৪ অঙ্কের সাথে `#abcd` এরা মিলবে না।

Diff for: 9-regular-expressions/11-regexp-groups/03-find-decimal-numbers/solution.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
A positive number with an optional decimal part is (per previous task): `pattern:\d+(\.\d+)?`.
1+
আমরা পূর্বের চ্যাপ্টারে ডেসিমেল সংখ্যা কে অপশনাল রেখে খুঁজার উপায় দেখেছিলাম: `pattern:\d+(\.\d+)?`
22

3-
Let's add the optional `pattern:-` in the beginning:
3+
ঋণাত্নক সংখ্যা খুঁজার জন্য শুরুতে `pattern:-` কে অপশনাল হিসেবে যোগ করি:
44

55
```js run
66
let regexp = /-?\d+(\.\d+)?/g;

Diff for: 9-regular-expressions/11-regexp-groups/03-find-decimal-numbers/task.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# Find all numbers
1+
# সকল নাম্বার খুঁজুন
22

3-
Write a regexp that looks for all decimal numbers including integer ones, with the floating point and negative ones.
3+
সকল ডেসিমেল (পূর্ণ সংখ্যা এবং ঋণাত্নক) সংখ্যা খুঁজার একটি রেগুলার এক্সপ্রেশন লিখুন।
44

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

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

1010
let str = "-1.5 0 2 -123.4.";
1111

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

+23-22
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,45 @@
1-
A regexp for a number is: `pattern:-?\d+(\.\d+)?`. We created it in previous tasks.
1+
সংখ্যা খুঁজার রেগুলার এক্সপ্রেশন: `pattern:-?\d+(\.\d+)?`। যা আমরা পূর্বের টাস্কে করেছিলাম।
22

3-
An operator is `pattern:[-+*/]`. The hyphen `pattern:-` goes first in the square brackets, because in the middle it would mean a character range, while we just want a character `-`.
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) {

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
# Parse an expression
1+
# এক্সপ্রেশনকে পার্স
22

3-
An arithmetical expression consists of 2 numbers and an operator between them, for instance:
3+
একটি গাণিতিক সমীকরণে দুটি নাম্বার এবং তাদের মাঝে একটি গাণিতিক চিহ্ন আছে, যেমন:
44

55
- `1 + 2`
66
- `1.2 * 3.4`
77
- `-3 / -6`
88
- `-2 - 2`
99

10-
The operator is one of: `"+"`, `"-"`, `"*"` or `"/"`.
10+
গাণিতিক চিহ্নগুলো হল: `"+"`, `"-"`, `"*"` অথবা `"/"`
1111

12-
There may be extra spaces at the beginning, at the end or between the parts.
12+
এখানে সমীকরণের শুরুতে,মাঝে এবং শেষে অতিরিক্ত স্পেস থাকতে পারে।
1313

14-
Create a function `parse(expr)` that takes an expression and returns an array of 3 items:
14+
একটি ফাংশন লিখুন যা `parse(expr)` একটি সমীকরণ নিবে এবং তাদের কে একটি অ্যারের ৩ টি উপাদান হিসেবে রিটার্ন করবে:
1515

16-
1. The first number.
17-
2. The operator.
18-
3. The second number.
16+
১. প্রথম সংখ্যাটি।
17+
২. গাণিতিক চিহ্নটি।
18+
৩. দ্বিতীয় সংখ্যাটি।
1919

20-
For example:
20+
যেমন:
2121

2222
```js
2323
let [a, op, b] = parse("1.2 * 3.4");

0 commit comments

Comments
 (0)