From 32665f022523bfac67f3bfc4be857d324c8b34b2 Mon Sep 17 00:00:00 2001 From: Saiful Date: Mon, 11 Jan 2021 10:06:37 +0600 Subject: [PATCH 1/9] wip capturing group --- .../11-regexp-groups/article.md | 90 +++++++++---------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/9-regular-expressions/11-regexp-groups/article.md b/9-regular-expressions/11-regexp-groups/article.md index ab25066d7..fc6407ba6 100644 --- a/9-regular-expressions/11-regexp-groups/article.md +++ b/9-regular-expressions/11-regexp-groups/article.md @@ -1,31 +1,31 @@ -# Capturing groups +# গ্রুপ ক্যাপচারিং -A part of a pattern can be enclosed in parentheses `pattern:(...)`. This is called a "capturing group". +প্যাটার্নের কোন একটা অংশকে প্যারেন্টেসিস `pattern:(...)` দ্বারা লিখাকে "গ্রুপ ক্যাপচারিং" বলে। -That has two effects: +এর ফলে ফলাফলে দুটি পরিবর্তন আছে: -1. It allows to get a part of the match as a separate item in the result array. -2. If we put a quantifier after the parentheses, it applies to the parentheses as a whole. +১. এটি দ্বারা লব্ধ ফলাফলের অ্যারেতে কোন একটা অংশকে আলাদা পজিশনে রাখা যায়। +২. যদি প্যারেন্টেসিসের পরে আমরা কোয়ান্টিফায়ার রাখি, এটি সম্পূর্ন গ্রুপের জন্য কাজ করবে। -## Examples +## উদাহরণ -Let's see how parentheses work in examples. +চলুন উদাহরণ দিয়ে দেখি গ্রুপ ক্যাপচারিং কিভাবে কাজ করে। -### Example: gogogo +### উদাহরণ: gogogo -Without parentheses, the pattern `pattern:go+` means `subject:g` character, followed by `subject:o` repeated one or more times. For instance, `match:goooo` or `match:gooooooooo`. +প্যারেন্টেসিস ছাড়া, এই প্যাটার্নটি `pattern:go+` দ্বারা বুঝায় `subject:g` এবং `subject:o` এই দুটি ক্যারাক্টার এক বা একাধিকবার পুনরাবৃত্তি হবে। উদাহরণস্বরুপ, `match:goooo` অথবা `match:gooooooooo`। -Parentheses group characters together, so `pattern:(go)+` means `match:go`, `match:gogo`, `match:gogogo` and so on. +প্যারেন্টেসিস দ্বারা গ্রুপ ক্যারাক্টারগুলো একসাথে বুঝায়, সুতরাং `pattern:(go)+` দ্বারা প্রাপ্তমিলগুলো হতে পারে `match:go`, `match:gogo`, `match:gogogo` অনুরূপ আরো অনেক। ```js run alert( 'Gogogo now!'.match(/(go)+/i) ); // "Gogogo" ``` -### Example: domain +### উদাহরণ: ডোমেন -Let's make something more complex -- a regular expression to search for a website domain. +চলুন আরো কঠিন কিছু করি -- রেগুলার এক্সপ্রেশন দ্বারা ওয়েবসাইটের ডোমেন খুঁজে বের করি। -For example: +যেমন: ``` mail.com @@ -33,9 +33,9 @@ users.mail.com smith.users.mail.com ``` -As we can see, a domain consists of repeated words, a dot after each one except the last one. +এইক্ষেত্রে আমরা দেখছি, ডোমেনে শেষ শব্দটি ব্যতীত শব্দের শেষে একটি ডট থাকবে। -In regular expressions that's `pattern:(\w+\.)+\w+`: +রেগুলার এক্সপ্রেশন আমরা এটি এভাবে লিখতে পারি `pattern:(\w+\.)+\w+`: ```js run let regexp = /(\w+\.)+\w+/g; @@ -43,17 +43,17 @@ let regexp = /(\w+\.)+\w+/g; alert( "site.com my.site.com".match(regexp) ); // site.com,my.site.com ``` -The search works, but the pattern can't match a domain with a hyphen, e.g. `my-site.com`, because the hyphen does not belong to class `pattern:\w`. +এটি কাজ করছে, কিন্তু উপরের প্যাটার্নটি হাইফেনসহ ডোমেনের জন্য সঠিকভাবে কাজ করবে না, যেমন. `my-site.com`, কেননা `pattern:\w` এই ক্যারাক্টার ক্লাস দ্বারা হাইফেনকে নির্দেশিত করা যায় না। -We can fix it by replacing `pattern:\w` with `pattern:[\w-]` in every word except the last one: `pattern:([\w-]+\.)+\w+`. +`pattern:\w` এর পরিবর্তে `pattern:[\w-]` লিখার মাধ্যমে আমরা এটিকে নির্ভুল করতে পারি সুতরাং প্যাটার্নটি হবে: `pattern:([\w-]+\.)+\w+`। -### Example: email +### উদাহরণ: ইমেইল -The previous example can be extended. We can create a regular expression for emails based on it. +পূর্ববর্তী উদাহরণটিকে কিছুটা বর্ধিত করে আমরা ইমেইল এর জন্য একটি রেগুলার এক্সপ্রেশন লিখতে পারি। -The email format is: `name@domain`. Any word can be the name, hyphens and dots are allowed. In regular expressions that's `pattern:[-.\w]+`. +ইমেইল এর ফরম্যাট: `name@domain`। নামের মধ্যে ডট হাইফেন ইত্যাদি থাকতে পারে। সুতরাং রেগুলার এক্সপ্রেশনটি হবে `pattern:[-.\w]+`। -The pattern: +প্যাটার্ন: ```js run let regexp = /[-.\w]+@([\w-]+\.)+[\w-]+/g; @@ -61,24 +61,24 @@ let regexp = /[-.\w]+@([\w-]+\.)+[\w-]+/g; alert("my@mail.com @ his@site.com.uk".match(regexp)); // my@mail.com, his@site.com.uk ``` -That regexp is not perfect, but mostly works and helps to fix accidental mistypes. The only truly reliable check for an email can only be done by sending a letter. +এটি পুরোপুরি নির্ভুল নই, কিন্তু বেশিরভাগক্ষেত্রে অ্যাক্সিডেন্টালি ভুল টাইপিং এড়ানোর জন্য কাজের। আমরা একটি ইমেইল নির্ভুল কিনা তা যাচাই করতে পারি শুধুমাত্র ইমেইল প্রেরণের মাধ্যমে। -## Parentheses contents in the match +## ফলাফলে প্যারেন্টেসিসের কন্টেন্টগুলো কিভাবে থাকে -Parentheses are numbered from left to right. The search engine memorizes the content matched by each of them and allows to get it in the result. +প্যারেন্টেসিসগুলোকে বাম থেকে ডানে হিসেব করা হয়। সার্চ ইঞ্জিন মিলকৃত সকল কন্টেন্টকে মনে রাখে এবং ফলাফলে এদের যুক্ত করে। -The method `str.match(regexp)`, if `regexp` has no flag `g`, looks for the first match and returns it as an array: +`str.match(regexp)` মেথড, যদি `regexp` কোন `g` ফ্ল্যাগ না থাকে, প্রথম মিলটি খুঁজে এবং এটি অ্যারে হিসেবে দেখায়: -1. At index `0`: the full match. -2. At index `1`: the contents of the first parentheses. -3. At index `2`: the contents of the second parentheses. -4. ...and so on... +১. `0` তম ইন্ডেক্সে: সম্পূর্ণ মিলটি। +২. `1` তম ইন্ডেক্সে: প্রথম প্যারেন্টেসিসের মিলগুলো। +৩. `2` তম ইন্ডেক্সে: দ্বিতীয় প্যারেন্টেসিসের মিলগুলো। +৪. ...এভাবেই চলতে থাকে... -For instance, we'd like to find HTML tags `pattern:<.*?>`, and process them. It would be convenient to have tag content (what's inside the angles), in a separate variable. +উদাহরণস্বরূপ, আমরা এইচটিএমএল ট্যাগ `pattern:<.*?>` খুঁজে পেতে চাই, এবং এদের নিয়ে কাজ করতে চাই। এজন্য আমাদের ট্যাগগুলো এবং ট্যাগের নাম গুলো আলাদা আলাদা ভ্যারিয়েবলে রাখা সুবিধাজনক। -Let's wrap the inner content into parentheses, like this: `pattern:<(.*?)>`. +চলুন ট্যাগনামগুলোকে আমরা প্যারেন্টেসিসের দ্বারা আবদ্ধ করি, এভাবে: `pattern:<(.*?)>`। -Now we'll get both the tag as a whole `match:

` and its contents `match:h1` in the resulting array: +এখন আমরা পুরো ট্যাগটি `match:

` এবং ট্যাগ নামটি `match:h1` লব্ধ ফলাফলে অ্যারে হিসেবে পাব: ```js run let str = '

Hello, world!

'; @@ -89,23 +89,23 @@ alert( tag[0] ); //

alert( tag[1] ); // h1 ``` -### Nested groups +### নেস্টেড গ্রুপ -Parentheses can be nested. In this case the numbering also goes from left to right. +প্যারেন্টেসিসগুলো নেস্টেডও হতে পারে। এক্ষেত্রেও ফলাফলে এরা বাম থেকে ডানে আসবে। -For instance, when searching a tag in `subject:` we may be interested in: +উদাহরণস্বরূপ, যখন আমরা এই ধরণের ট্যাগে `subject:` অনুসন্ধান করব আমরা ফলাফলটিকে নিম্নোক্তভাবে রাখতে পারব: -1. The tag content as a whole: `match:span class="my"`. -2. The tag name: `match:span`. -3. The tag attributes: `match:class="my"`. +১. পুরো কন্টেন্টটি: `match:span class="my"`। +২. ট্যাগ নামটি: `match:span`। +৩. ট্যাগ অ্যাট্রিবিউট: `match:class="my"`। -Let's add parentheses for them: `pattern:<(([a-z]+)\s*([^>]*))>`. +সুতরাং নেস্টেড প্যাটার্নটি হবে এমন: `pattern:<(([a-z]+)\s*([^>]*))>`। -Here's how they are numbered (left to right, by the opening paren): +দেখুন এরা কিভাবে ক্রম করে (বাম থেকে ডানে, প্যারেন্টেসিসের উপর ভিত্তি করে): ![](regexp-nested-groups-pattern.svg) -In action: +উদাহরণ: ```js run let str = ''; @@ -119,13 +119,13 @@ alert(result[2]); // span alert(result[3]); // class="my" ``` -The zero index of `result` always holds the full match. +`result` এর শূন্যতম ইন্ডেক্সে সম্পূর্ণ কন্টেন্টটি। -Then groups, numbered from left to right by an opening paren. The first group is returned as `result[1]`. Here it encloses the whole tag content. +এরপর গ্রুপিং, ওপেনিং প্যারেন্টেসিসের এর উপর নির্ভর করে বাম থেকে ডানে। প্রথম গ্রুপটি হবে `result[1]`। এখানে পুরো ট্যাগ কন্টেন্টটি আসবে। -Then in `result[2]` goes the group from the second opening paren `pattern:([a-z]+)` - tag name, then in `result[3]` the tag: `pattern:([^>]*)`. +এরপর `result[2]` হল দ্বিতীয় ওপেনিং প্যারেন্টেসিসের `pattern:([a-z]+)` কন্টেন্ট - ট্যাগ নাম, এরপর `result[3]` ট্যাগ অ্যাট্রিবিউট: `pattern:([^>]*)`। -The contents of every group in the string: +স্ট্রিংয়ের প্রতিটি গ্রুপ: ![](regexp-nested-groups-matches.svg) From 32857007f437ff76dbd1c8db979d4ef332ca87d8 Mon Sep 17 00:00:00 2001 From: Saiful Date: Wed, 13 Jan 2021 09:58:43 +0600 Subject: [PATCH 2/9] done group capturing --- .../11-regexp-groups/article.md | 159 +++++++++--------- 1 file changed, 79 insertions(+), 80 deletions(-) diff --git a/9-regular-expressions/11-regexp-groups/article.md b/9-regular-expressions/11-regexp-groups/article.md index fc6407ba6..d3522df89 100644 --- a/9-regular-expressions/11-regexp-groups/article.md +++ b/9-regular-expressions/11-regexp-groups/article.md @@ -23,7 +23,7 @@ alert( 'Gogogo now!'.match(/(go)+/i) ); // "Gogogo" ### উদাহরণ: ডোমেন -চলুন আরো কঠিন কিছু করি -- রেগুলার এক্সপ্রেশন দ্বারা ওয়েবসাইটের ডোমেন খুঁজে বের করি। +চলুন আরো কঠিন কিছু করি -- রেগুলার এক্সপ্রেশন দ্বারা ওয়েবসাইটের ডোমেন খুঁজে বের করা। যেমন: @@ -33,7 +33,7 @@ users.mail.com smith.users.mail.com ``` -এইক্ষেত্রে আমরা দেখছি, ডোমেনে শেষ শব্দটি ব্যতীত শব্দের শেষে একটি ডট থাকবে। +এইক্ষেত্রে আমরা দেখছি, ডোমেনে শেষ শব্দটি ব্যতীত প্রতিটি শব্দের শেষে একটি ডট থাকবে। রেগুলার এক্সপ্রেশন আমরা এটি এভাবে লিখতে পারি `pattern:(\w+\.)+\w+`: @@ -63,22 +63,22 @@ alert("my@mail.com @ his@site.com.uk".match(regexp)); // my@mail.com, his@site.c এটি পুরোপুরি নির্ভুল নই, কিন্তু বেশিরভাগক্ষেত্রে অ্যাক্সিডেন্টালি ভুল টাইপিং এড়ানোর জন্য কাজের। আমরা একটি ইমেইল নির্ভুল কিনা তা যাচাই করতে পারি শুধুমাত্র ইমেইল প্রেরণের মাধ্যমে। -## ফলাফলে প্যারেন্টেসিসের কন্টেন্টগুলো কিভাবে থাকে +## রেজাল্টে প্যারেন্টেসিসের কন্টেন্টগুলো কিভাবে থাকে -প্যারেন্টেসিসগুলোকে বাম থেকে ডানে হিসেব করা হয়। সার্চ ইঞ্জিন মিলকৃত সকল কন্টেন্টকে মনে রাখে এবং ফলাফলে এদের যুক্ত করে। +প্যারেন্টেসিসের কন্টেন্ট গুলোকে বাম থেকে ডানে হিসেব করা হয়। সার্চ ইঞ্জিন মিলকৃত সকল কন্টেন্টকে মনে রাখে এবং রেজাল্টে এদের পাওয়া যায়। -`str.match(regexp)` মেথড, যদি `regexp` কোন `g` ফ্ল্যাগ না থাকে, প্রথম মিলটি খুঁজে এবং এটি অ্যারে হিসেবে দেখায়: +`str.match(regexp)` মেথড, যদি `regexp` কোন `g` ফ্ল্যাগ না থাকে, তাহলে প্রথম মিলটি খুঁজে এবং এটি অ্যারে হিসেবে দেখায়: -১. `0` তম ইন্ডেক্সে: সম্পূর্ণ মিলটি। -২. `1` তম ইন্ডেক্সে: প্রথম প্যারেন্টেসিসের মিলগুলো। -৩. `2` তম ইন্ডেক্সে: দ্বিতীয় প্যারেন্টেসিসের মিলগুলো। +১. `0` তম ইনডেক্সে: সম্পূর্ণ মিলটি। +২. `1` তম ইনডেক্সে: প্রথম প্যারেন্টেসিসের মিলগুলো। +৩. `2` তম ইনডেক্সে: দ্বিতীয় প্যারেন্টেসিসের মিলগুলো। ৪. ...এভাবেই চলতে থাকে... -উদাহরণস্বরূপ, আমরা এইচটিএমএল ট্যাগ `pattern:<.*?>` খুঁজে পেতে চাই, এবং এদের নিয়ে কাজ করতে চাই। এজন্য আমাদের ট্যাগগুলো এবং ট্যাগের নাম গুলো আলাদা আলাদা ভ্যারিয়েবলে রাখা সুবিধাজনক। +উদাহরণস্বরূপ, আমরা HTML ট্যাগ `pattern:<.*?>` খুঁজে পেতে চাই, এবং এদের নিয়ে কাজ করতে চাই। এজন্য আমাদের ট্যাগগুলো এবং ট্যাগের নাম গুলো আলাদা আলাদা ভ্যারিয়েবলে রাখা সুবিধাজনক। -চলুন ট্যাগনামগুলোকে আমরা প্যারেন্টেসিসের দ্বারা আবদ্ধ করি, এভাবে: `pattern:<(.*?)>`। +চলুন ট্যাগ নামগুলোকে আমরা প্যারেন্টেসিসের দ্বারা আবদ্ধ করি, এভাবে: `pattern:<(.*?)>`। -এখন আমরা পুরো ট্যাগটি `match:

` এবং ট্যাগ নামটি `match:h1` লব্ধ ফলাফলে অ্যারে হিসেবে পাব: +এখন আমরা পুরো ট্যাগটি `match:

` এবং ট্যাগ নামটি `match:h1` রেজাল্টে অ্যারে হিসেবে পাব: ```js run let str = '

Hello, world!

'; @@ -91,7 +91,7 @@ alert( tag[1] ); // h1 ### নেস্টেড গ্রুপ -প্যারেন্টেসিসগুলো নেস্টেডও হতে পারে। এক্ষেত্রেও ফলাফলে এরা বাম থেকে ডানে আসবে। +প্যারেন্টেসিসগুলো নেস্টেডও হতে পারে। এক্ষেত্রেও রেজাল্টে এরা বাম থেকে ডানে আসবে। উদাহরণস্বরূপ, যখন আমরা এই ধরণের ট্যাগে `subject:` অনুসন্ধান করব আমরা ফলাফলটিকে নিম্নোক্তভাবে রাখতে পারব: @@ -101,7 +101,7 @@ alert( tag[1] ); // h1 সুতরাং নেস্টেড প্যাটার্নটি হবে এমন: `pattern:<(([a-z]+)\s*([^>]*))>`। -দেখুন এরা কিভাবে ক্রম করে (বাম থেকে ডানে, প্যারেন্টেসিসের উপর ভিত্তি করে): +দেখুন এরা কিভাবে ক্রম হয় (প্যারেন্টেসিসের উপর ভিত্তি করে বাম থেকে ডানে): ![](regexp-nested-groups-pattern.svg) @@ -119,7 +119,7 @@ alert(result[2]); // span alert(result[3]); // class="my" ``` -`result` এর শূন্যতম ইন্ডেক্সে সম্পূর্ণ কন্টেন্টটি। +`result` এর শূন্যতম ইনডেক্সে সম্পূর্ণ কন্টেন্টটি। এরপর গ্রুপিং, ওপেনিং প্যারেন্টেসিসের এর উপর নির্ভর করে বাম থেকে ডানে। প্রথম গ্রুপটি হবে `result[1]`। এখানে পুরো ট্যাগ কন্টেন্টটি আসবে। @@ -129,49 +129,48 @@ alert(result[3]); // class="my" ![](regexp-nested-groups-matches.svg) -### Optional groups +### অপশনাল গ্রুপ -Even if a group is optional and doesn't exist in the match (e.g. has the quantifier `pattern:(...)?`), the corresponding `result` array item is present and equals `undefined`. +যদি কোন গ্রুপ অপশনাল হয় এবং কোন মিল না পায় (যেমন এই কোয়ান্টিফায়ারটি `pattern:(...)?`), `result` অ্যারেতে আইটেমটি `undefined` হিসেবে থাকবে। -For instance, let's consider the regexp `pattern:a(z)?(c)?`. It looks for `"a"` optionally followed by `"z"` optionally followed by `"c"`. +উদাহরণস্বরূপ, রেগুলার এক্সপ্রেশনটি দেখুন `pattern:a(z)?(c)?`। এটি প্রথমে `"a"` খুঁজে অতঃপর `"z"` এবং `"c"` কে অপশনাল হিসেবে খুঁজে। -If we run it on the string with a single letter `subject:a`, then the result is: +যদি আমরা একটি ক্যারাক্টার `subject:a` এর জন্য প্যাটার্নটি ব্যবহার করি, তাহলে ফলাফলটি হবে: ```js run let match = 'a'.match(/a(z)?(c)?/); alert( match.length ); // 3 -alert( match[0] ); // a (whole match) +alert( match[0] ); // a (সম্পূর্ন সাবজেক্ট) alert( match[1] ); // undefined alert( match[2] ); // undefined ``` +অ্যারেটির সাইজ `3`, কিন্তু গ্রুপ ইনডেক্স গুলো 'undefined'। -The array has the length of `3`, but all groups are empty. - -And here's a more complex match for the string `subject:ac`: +এখানে পূর্বেরটির চেয়ে আরেকটি জটিল সাব্জেক্ট আছে `subject:ac`: ```js run let match = 'ac'.match(/a(z)?(c)?/) alert( match.length ); // 3 -alert( match[0] ); // ac (whole match) -alert( match[1] ); // undefined, because there's nothing for (z)? +alert( match[0] ); // ac (সম্পূর্ন সাবজেক্ট) +alert( match[1] ); // undefined, কেননা (z)? এর সাথে কোন মিল নেই alert( match[2] ); // c ``` -The array length is permanent: `3`. But there's nothing for the group `pattern:(z)?`, so the result is `["ac", undefined, "c"]`. +অ্যারেটির সাইজ: `3`। কিন্তু `pattern:(z)?` এর জন্য কোন ফলাফল নেই, সুতরাং অ্যারেটি হবে `["ac", undefined, "c"]`। -## Searching for all matches with groups: matchAll +## সকল ম্যাচের জন্য গ্রুপ অনুসন্ধান: matchAll -```warn header="`matchAll` is a new method, polyfill may be needed" -The method `matchAll` is not supported in old browsers. +```warn header="`matchAll` হল একটি নতুন মেথড, এজন্য পলিফিলের দরকার হতে পারে" +`matchAll` পুরাতন ব্রাউজারের জন্য কাজ করবে না। -A polyfill may be required, such as . +এজন্য পলিফিলের দরকার, যেমন . ``` -When we search for all matches (flag `pattern:g`), the `match` method does not return contents for groups. +যখন আমরা সকল ম্যাচের জন্য ফ্ল্যাগ (`pattern:g`) দ্বারা অনুসন্ধান করব, `match` মেথডটি গ্রুপ কন্টেন্টগুলো রিটার্ন করে না। -For example, let's find all tags in a string: +যেমন, স্ট্রিংটি হতে সকল ট্যাগগুলো খুঁজি: ```js run let str = '

'; @@ -181,55 +180,55 @@ let tags = str.match(/<(.*?)>/g); alert( tags ); //

,

``` -The result is an array of matches, but without details about each of them. But in practice we usually need contents of capturing groups in the result. +রেজাল্টে আমরা ম্যাচকৃত সকল অ্যারে দেখি, কিন্তু তাদের প্রত্যেকের গ্রুপ কন্টেন্টের বিস্তারিত নেই। কিন্তু সাধারণত আমাদের ক্যাপচারিং গ্রুপের কন্টেন্ট গুলো রেজাল্টে লাগতে পারে। -To get them, we should search using the method `str.matchAll(regexp)`. +এজন্য, আমাদের সার্চিংটা `str.matchAll(regexp)` এই মেথডের সাহায্যে চালাতে হবে। -It was added to JavaScript language long after `match`, as its "new and improved version". +এটি জাভাস্ক্রিপ্টে `match` মেথডের অনেক পরে সংযুক্ত হয়েছে, এজন্য এটি "নতুন এবং উন্নত ভার্সন"। -Just like `match`, it looks for matches, but there are 3 differences: +`match` এর মত এটিও মিলগুলো খুঁজে, কিন্তু `match` এর সাথে ৩টি পার্থক্য আছে: -1. It returns not an array, but an iterable object. -2. When the flag `pattern:g` is present, it returns every match as an array with groups. -3. If there are no matches, it returns not `null`, but an empty iterable object. +১. এটি অ্যারে রিটার্নের পরিবর্তে একটি ইটারেবল অবজেক্ট রিটার্ন করে। +২. যখন `pattern:g` এই ফ্ল্যাগটি থাকে, এটি প্রতিটি মিলকে গ্রুপ কন্টেন্ট সহ একটি অ্যারে আকারে থাকে। +৩. যদি কোন মিল না থাকে, এটি `null` রিটার্নের পরিবর্তে একটি এম্পটি ইটারেবল অবজেক্ট রিটার্ন করে। -For instance: +উদাহরণস্বরূপ: ```js run let results = '

'.matchAll(/<(.*?)>/gi); -// results - is not an array, but an iterable object +// results - অ্যারে পরিবর্তে একটি ইটারেবল অবজেক্ট alert(results); // [object RegExp String Iterator] alert(results[0]); // undefined (*) -results = Array.from(results); // let's turn it into array +results = Array.from(results); // অ্যারেতে নিয়ে যায় alert(results[0]); //

,h1 (1st tag) alert(results[1]); //

,h2 (2nd tag) ``` -As we can see, the first difference is very important, as demonstrated in the line `(*)`. We can't get the match as `results[0]`, because that object isn't pseudoarray. We can turn it into a real `Array` using `Array.from`. There are more details about pseudoarrays and iterables in the article . +আমরা দেখছি, প্রথম পার্থক্যটি অনেক গুরত্বপূর্ণ, `(*)` দ্বারা নির্দেশিত লাইনটি খেয়াল করুন। আমরা মিলটিকে `results[0]` এর মধ্যে পায় না, কেননা অবজেক্টটি সুডোঅ্যারে নই। আমরা এটিকে `Array.from` এর মাধ্যমে `Array` তে নিতে পারি। সুডোঅ্যারে এবং ইটারেবল সম্পর্কে বিস্তারিত জানতে পারবেন এই আর্টিকেলে । -There's no need in `Array.from` if we're looping over results: +`Array.from` ছাড়াও আমরা লুপের মাধ্যমে রেজাল্ট গুলো দেখতে পারি: ```js run let results = '

'.matchAll(/<(.*?)>/gi); for(let result of results) { alert(result); - // первый вывод:

,h1 - // второй:

,h2 + // প্রথম অ্যালার্ট:

,h1 + // দ্বিতীয়:

,h2 } ``` -...Or using destructuring: +...অথবা destructuring ব্যবহারের মাধ্যমে: ```js let [tag1, tag2] = '

'.matchAll(/<(.*?)>/gi); ``` -Every match, returned by `matchAll`, has the same format as returned by `match` without flag `pattern:g`: it's an array with additional properties `index` (match index in the string) and `input` (source string): +`matchAll` দ্বারা রিটার্নকৃত রেজাল্টের প্রতিটি ম্যাচ ফ্ল্যাগ `pattern:g` ছাড়া `match` মেথডের মত: তবে এর সাথে দুটি অতিরিক্ত প্রোপার্টি থাকে `index` (স্ট্রিংয়ে মিলকৃত ইনডেক্সটি) এবং `input` (সোর্স স্ট্রিং): ```js run let results = '

'.matchAll(/<(.*?)>/gi); @@ -242,23 +241,23 @@ alert( tag1.index ); // 0 alert( tag1.input ); //

``` -```smart header="Why is a result of `matchAll` an iterable object, not an array?" -Why is the method designed like that? The reason is simple - for the optimization. +```smart header="`matchAll` এর রেজাল্ট অ্যারে না হয়ে ইটারেবল অবজেক্ট কেন?" +কেন এই মেথডটি এভাবে ডিজাইন করা হয়েছে? এর কারণ সহজ - অপ্টিমাইজেশনের জন্য। -The call to `matchAll` does not perform the search. Instead, it returns an iterable object, without the results initially. The search is performed each time we iterate over it, e.g. in the loop. +`matchAll` কল হলে এটি স্ট্রিংয়ে সার্চ করে না। তার পরিবর্তে, রেজাল্ট ইনিশিয়াল না হয়ে এটি একটি ইটারেবল অবজেক্ট রিটার্ন করে। এবং ইটারেটরের সময় সার্চ সম্পন্ন হয়, যেমন লুপে। -So, there will be found as many results as needed, not more. +সুতরাং, এটি প্রয়োজনমত রেজাল্ট খুঁজে পায়, এর বেশি না। -E.g. there are potentially 100 matches in the text, but in a `for..of` loop we found 5 of them, then decided it's enough and make a `break`. Then the engine won't spend time finding other 95 mathces. +যেমন কোন টেক্সটে ১০০ টি ম্যাচ আছে, এবং `for..of` এর মাধ্যমে আমরা ৫টি মিল খুঁজি, তারপর আমরা লুপ হতে `break` এর মাধ্যমে বের হয়ে যেতে পারি। সুতরাং ইঞ্জিনের বাকী ৯৫টি মিল খুঁজার জন্য অতিরিক্ত সময় অতিবাহিত করা লাগবে না। ``` -## Named groups +## গ্রুপের নামকরণ -Remembering groups by their numbers is hard. For simple patterns it's doable, but for more complex ones counting parentheses is inconvenient. We have a much better option: give names to parentheses. +ইনডেক্স দিয়ে গ্রুপগুলোকে মনে রাখা কষ্টসাধ্য। সহজ প্যাটার্নগুলোর জন্য এটি সহনীয়, তবে জটিল প্যাটার্নগুলোর জন্য প্যারেন্টেসিস গুনে ইনডেক্সিং করা অসুবিধাজনক। আমাদের কাছে প্যারেন্টেসিসের নামকরণের একটি উপায় আছে। -That's done by putting `pattern:?` immediately after the opening paren. +শুরুর প্যারেন্টেসিসের পর `pattern:?` লিখার মাধ্যমে আমরা নাম দিতে পারি। -For example, let's look for a date in the format "year-month-day": +যেমন, তারিখকে আমরা এভাবে ফরম্যাট করতে পারি "year-month-day": ```js run *!* @@ -273,11 +272,11 @@ alert(groups.month); // 04 alert(groups.day); // 30 ``` -As you can see, the groups reside in the `.groups` property of the match. +এখানে দেখতে পাচ্ছি, ক্যাপচারিং গ্রুপগুলো `.groups` এর প্রপার্টি হিসেবে আছে। -To look for all dates, we can add flag `pattern:g`. +একাধিক তারিখ বের করার জন্য আমাদের `pattern:g` এর সাহায্য নেয়া লাগবে। -We'll also need `matchAll` to obtain full matches, together with groups: +গ্রুপের সাথে সম্পূর্ণ মিল খুঁজার জন্য `matchAll` মেথডের সাহায্য লাগবে: ```js run let dateRegexp = /(?[0-9]{4})-(?[0-9]{2})-(?[0-9]{2})/g; @@ -295,11 +294,11 @@ for(let result of results) { } ``` -## Capturing groups in replacement +## রিপ্লেসের জন্য ক্যাপচারিং গ্রুপ -Method `str.replace(regexp, replacement)` that replaces all matches with `regexp` in `str` allows to use parentheses contents in the `replacement` string. That's done using `pattern:$n`, where `pattern:n` is the group number. +`str.replace(regexp, replacement)` মেথডের সাহায্যে `regexp` এর সাথে মিলকৃত কন্টেন্ট সমূহকে রিপ্লেস করা যায়, এবং `str` এর `replacement` এ প্যারেন্টেসিস কন্টেন্টসমূহ ব্যবহার করতে পারি। এটি করা যায় `pattern:$n` এর মাধ্যমে, যেখানে `pattern:n` হল গ্রুপ নাম্বার। -For example, +যেমন, ```js run let str = "John Bull"; @@ -308,9 +307,9 @@ let regexp = /(\w+) (\w+)/; alert( str.replace(regexp, '$2, $1') ); // Bull, John ``` -For named parentheses the reference will be `pattern:$`. +গ্রুপের নামকরণ এর ক্ষেত্রে ব্যবহার করা যায় এভাবে `pattern:$`। -For example, let's reformat dates from "year-month-day" to "day.month.year": +যেমন, চলুন আমাদের তারিখটিকে "year-month-day" থেকে "day.month.year" এভাবে সাজাই: ```js run let regexp = /(?[0-9]{4})-(?[0-9]{2})-(?[0-9]{2})/g; @@ -321,21 +320,21 @@ alert( str.replace(regexp, '$.$.$') ); // 30.10.2019, 01.01.2020 ``` -## Non-capturing groups with ?: +## নন-ক্যাপচারিং গ্রুপ ?: -Sometimes we need parentheses to correctly apply a quantifier, but we don't want their contents in results. +অনেক সময় আমাদের গ্রুপ ক্যাপচারিং এমনভাবে করা লাগে, যেন ওই গ্রুপের কন্টেন্ট রেজাল্টের মধ্যে না আছে। -A group may be excluded by adding `pattern:?:` in the beginning. +একটি গ্রপের কন্টেন্ট কে রেজাল্ট থেকে বাদ দিতে পারি শুরুর প্যারেন্টেসিস পর `pattern:?:` দেয়ার মাধ্যমে। -For instance, if we want to find `pattern:(go)+`, but don't want the parentheses contents (`go`) as a separate array item, we can write: `pattern:(?:go)+`. +যেমন, আমরা `pattern:(go)+` এটিকে খুঁজতে চাই, কিন্তু আমরা (`go`) এর কন্টেন্টকে অ্যারের আলাদা আইটেম হিসেবে চাই না, সুতরাং আমরা এভাবে লিখতে পারি: `pattern:(?:go)+` -In the example below we only get the name `match:John` as a separate member of the match: +সুতরাং এজন্য আমরা শুধু এই নামটি `match:John` ১ম ইনডেক্সে পাব: ```js run let str = "Gogogo John!"; *!* -// ?: exludes 'go' from capturing +// ?: এর দ্বারা 'go' কে ক্যাপচারিং হতে বাদ দিতে পারি let regexp = /(?:go)+ (\w+)/i; */!* @@ -343,22 +342,22 @@ let result = str.match(regexp); alert( result[0] ); // Gogogo John (full match) alert( result[1] ); // John -alert( result.length ); // 2 (no more items in the array) +alert( result.length ); // 2 (আর কোন আইটেম নেয়) ``` -## Summary +## সারাংশ -Parentheses group together a part of the regular expression, so that the quantifier applies to it as a whole. +প্যারেন্টেসিস গ্রুপগুলো রেগুলার এক্সপ্রেশনের একটি অংশ, সুতরাং কোয়ান্টিফায়ারগুলো এদের সম্পূর্নটার উপর কাজ করবে। -Parentheses groups are numbered left-to-right, and can optionally be named with `(?...)`. +প্যারেন্টেসিস গ্রুপগুলো বাম থেকে ডানে ক্রম করা হয়, এবং চাইলে এদের নামকরণও করা যেতে পারে `(?...)`। -The content, matched by a group, can be obtained in the results: +কন্টেন্ট যখন গ্রুপদ্বারা ম্যাচ হয়, তখন এদের রেজাল্টে পাওয়া যায়: -- The method `str.match` returns capturing groups only without flag `pattern:g`. -- The method `str.matchAll` always returns capturing groups. +- `str.match` মেথডটি এই ফ্ল্যাগছাড়া `pattern:g` ক্যাপচারিং করলে ক্যাপচারিং কন্টেন্টগুলো রিটার্ন করে। +- `str.matchAll` মেথডটি সর্বদা ক্যাপচারিং গ্রুপগুলো রিটার্ন করে। -If the parentheses have no name, then their contents is available in the match array by its number. Named parentheses are also available in the property `groups`. +যদি প্যারেন্টেসিসে নাম না থাকে, তাহলে অ্যারেতে এদের গ্রুপের ক্রমানুসারে পাওয়া যাবে। এবং গ্রুপের নামকরণ করলে এরা `groups` এর প্রপার্টি হিসেবে থাকবে। -We can also use parentheses contents in the replacement string in `str.replace`: by the number `$n` or the name `$`. +গ্রুপ কন্টেন্টগুলো আমরা রিপ্লেসম্যান্টের সময় ব্যবহার করতে পারব `str.replace`: ইনডেক্স এর ক্ষেত্রে `$n` এবং নামের ক্ষেত্রে `$`। -A group may be excluded from numbering by adding `pattern:?:` in its start. That's used when we need to apply a quantifier to the whole group, but don't want it as a separate item in the results array. We also can't reference such parentheses in the replacement string. +আমরা গ্রুপের শুরুতে `pattern:?:` ব্যবহারের মাধ্যমে রেজাল্ট হতে এদের বাদ দিতে পারি। আমরা যখন সম্পূর্ন গ্রুপে কোয়ান্টিফায়ার ব্যবহার করব, কিন্তু রেজাল্টে এদের আলাদা করে চায় না তখন এটি ব্যবহার করতে পারি। এছাড়াও স্ট্রিং রিপ্লেসম্যান্টের সময় আমরা প্যারেন্টেসিস ব্যবহার করতে পারব না। \ No newline at end of file From 92fc6ea5af1ec0300b15c9db810902323aef843c Mon Sep 17 00:00:00 2001 From: Saiful Date: Wed, 13 Jan 2021 10:23:52 +0600 Subject: [PATCH 3/9] wip task-1 --- .../11-regexp-groups/01-test-mac/solution.md | 6 +++--- .../11-regexp-groups/01-test-mac/task.md | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/9-regular-expressions/11-regexp-groups/01-test-mac/solution.md b/9-regular-expressions/11-regexp-groups/01-test-mac/solution.md index 26f7888f7..bb50adb55 100644 --- a/9-regular-expressions/11-regexp-groups/01-test-mac/solution.md +++ b/9-regular-expressions/11-regexp-groups/01-test-mac/solution.md @@ -1,8 +1,8 @@ -A two-digit hex number is `pattern:[0-9a-f]{2}` (assuming the flag `pattern:i` is set). +একটি দুই অঙ্কবিশিষ্ট হেক্সাডেসিমেল নাম্বারের প্যাটার্ন হল `pattern:[0-9a-f]{2}` (ধরে নিই, `pattern:i` ফ্ল্যাগ সেট আছে)। -We need that number `NN`, and then `:NN` repeated 5 times (more numbers); +সুতরাং আমাদের এই নাম্বারটি `NN` লাগবে, এবং এটির `:NN` ৫ বার পুনরাবৃত্তি হবে; -The regexp is: `pattern:[0-9a-f]{2}(:[0-9a-f]{2}){5}` +রেগুলার এক্সপ্রেশনটি হবে: `pattern:[0-9a-f]{2}(:[0-9a-f]{2}){5}` 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:^...$`. diff --git a/9-regular-expressions/11-regexp-groups/01-test-mac/task.md b/9-regular-expressions/11-regexp-groups/01-test-mac/task.md index 029a4803a..5d4bf9cc2 100644 --- a/9-regular-expressions/11-regexp-groups/01-test-mac/task.md +++ b/9-regular-expressions/11-regexp-groups/01-test-mac/task.md @@ -1,20 +1,20 @@ -# Check MAC-address +# MAC-address যাচাই -[MAC-address](https://en.wikipedia.org/wiki/MAC_address) of a network interface consists of 6 two-digit hex numbers separated by a colon. +[MAC-address](https://en.wikipedia.org/wiki/MAC_address) হল নেটওয়ার্ক ইন্টারফেসের ৬ টি দুই অঙ্কবিশিষ্ট একটি হেক্সাডেসিমেল নাম্বার যা কোলন দ্বারা পৃথক থাকে। -For instance: `subject:'01:32:54:67:89:AB'`. +যেমন: `subject:'01:32:54:67:89:AB'`। -Write a regexp that checks whether a string is MAC-address. +MAC-address যাচাইয়ের জন্য একটি রেগুলার এক্সপ্রেশন লিখুন। -Usage: +উদাহরণস্বরুপ: ```js let regexp = /your regexp/; -alert( regexp.test('01:32:54:67:89:AB') ); // true +alert( regexp.test('01:32:54:67:89:AB') ); // সত্য -alert( regexp.test('0132546789AB') ); // false (no colons) +alert( regexp.test('0132546789AB') ); // মিথ্যা (কোলন নেয়) -alert( regexp.test('01:32:54:67:89') ); // false (5 numbers, must be 6) +alert( regexp.test('01:32:54:67:89') ); // মিথ্যা (৫টি নাম্বার, অবশ্যই ৬টি হতে হবে) -alert( regexp.test('01:32:54:67:89:ZZ') ) // false (ZZ ad the end) +alert( regexp.test('01:32:54:67:89:ZZ') ) // মিথ্যা (শেষে ZZ) ``` From 3211858231629bb9154d9c10d8ceb84ae7ea8c9d Mon Sep 17 00:00:00 2001 From: Saiful Date: Wed, 13 Jan 2021 11:49:10 +0600 Subject: [PATCH 4/9] task-1 done --- .../11-regexp-groups/01-test-mac/solution.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/9-regular-expressions/11-regexp-groups/01-test-mac/solution.md b/9-regular-expressions/11-regexp-groups/01-test-mac/solution.md index bb50adb55..e9a28b66c 100644 --- a/9-regular-expressions/11-regexp-groups/01-test-mac/solution.md +++ b/9-regular-expressions/11-regexp-groups/01-test-mac/solution.md @@ -2,20 +2,20 @@ সুতরাং আমাদের এই নাম্বারটি `NN` লাগবে, এবং এটির `:NN` ৫ বার পুনরাবৃত্তি হবে; -রেগুলার এক্সপ্রেশনটি হবে: `pattern:[0-9a-f]{2}(:[0-9a-f]{2}){5}` +সুতরাং রেগুলার এক্সপ্রেশনটি হবে: `pattern:[0-9a-f]{2}(:[0-9a-f]{2}){5}` -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:^...$`. +এখন চলুন ম্যাচটি শুরু থেকে শেষ পর্যন্ত সকল পুরো লাইনটি পাঠ করার উপযোগী করি। এজন্য সম্পূর্ন প্যাটার্নটি `pattern:^...$` এর মধ্যে লিখি। -Finally: +শেষ পর্যন্ত: ```js run let regexp = /^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}$/i; -alert( regexp.test('01:32:54:67:89:AB') ); // true +alert( regexp.test('01:32:54:67:89:AB') ); // সত্য -alert( regexp.test('0132546789AB') ); // false (no colons) +alert( regexp.test('0132546789AB') ); // মিথ্যা (কোলন নেয়) -alert( regexp.test('01:32:54:67:89') ); // false (5 numbers, need 6) +alert( regexp.test('01:32:54:67:89') ); // মিথ্যা (৫টি নাম্বার, অবশ্যই ৬টি হতে হবে) -alert( regexp.test('01:32:54:67:89:ZZ') ) // false (ZZ in the end) +alert( regexp.test('01:32:54:67:89:ZZ') ) // মিথ্যা (শেষে ZZ) ``` From 54722fd9272e418deffe121f0968c66672389319 Mon Sep 17 00:00:00 2001 From: Saiful Date: Wed, 13 Jan 2021 12:08:23 +0600 Subject: [PATCH 5/9] task-2 --- .../02-find-webcolor-3-or-6/solution.md | 12 ++++++------ .../11-regexp-groups/02-find-webcolor-3-or-6/task.md | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/9-regular-expressions/11-regexp-groups/02-find-webcolor-3-or-6/solution.md b/9-regular-expressions/11-regexp-groups/02-find-webcolor-3-or-6/solution.md index 0806dc4fd..8aea4299e 100644 --- a/9-regular-expressions/11-regexp-groups/02-find-webcolor-3-or-6/solution.md +++ b/9-regular-expressions/11-regexp-groups/02-find-webcolor-3-or-6/solution.md @@ -1,12 +1,12 @@ -A regexp to search 3-digit color `#abc`: `pattern:/#[a-f0-9]{3}/i`. +৩ অঙ্কবিশিষ্ট সংখ্যা খুঁজার রেগুলার এক্সপ্রেশন হল `#abc`: `pattern:/#[a-f0-9]{3}/i`। -We can add exactly 3 more optional hex digits. We don't need more or less. The color has either 3 or 6 digits. +এরপর আমরা শুধুমাত্র আরো ৩অঙ্কবিশিষ্ট অপশনাল হেক্সাডেসিমেল নাম্বার খুঁজার প্যাটার্ন লিখব, আমাদের এর বেশি বা কমের জন্য লাগবে না। সুতরাং কালারটি হবে ৩ বা ৬ অঙ্কের। -Let's use the quantifier `pattern:{1,2}` for that: we'll have `pattern:/#([a-f0-9]{3}){1,2}/i`. +চলুন এই জন্য এই কোয়ান্টিফায়ারটি `pattern:{1,2}` ব্যবহার করি: আমাদের প্যাটার্নটি হবে `pattern:/#([a-f0-9]{3}){1,2}/i`। -Here the pattern `pattern:[a-f0-9]{3}` is enclosed in parentheses to apply the quantifier `pattern:{1,2}`. +এখানে আমরা এই প্যাটার্নটি `pattern:[a-f0-9]{3}` প্যারান্টেসিসের মধ্যে লিখব, যাতে এই কোয়ান্টিফায়ারটি `pattern:{1,2}` ব্যবহার করা যায়। -In action: +এখানে দেখুন: ```js run let regexp = /#([a-f0-9]{3}){1,2}/gi; @@ -16,7 +16,7 @@ let str = "color: #3f3; background-color: #AA00ef; and: #abcd"; alert( str.match(regexp) ); // #3f3 #AA00ef #abc ``` -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: +তবে এখানে একটি ছোট্ট সমস্যা আছে `match:#abc` এই স্ট্রিংয়ের জন্যও কাজ করবে `subject:#abcd`, যা সঠিক নয়। এজন্য আমাদের শেষে `pattern:\b` ব্যবহার করা লাগবে: ```js run let regexp = /#([a-f0-9]{3}){1,2}\b/gi; diff --git a/9-regular-expressions/11-regexp-groups/02-find-webcolor-3-or-6/task.md b/9-regular-expressions/11-regexp-groups/02-find-webcolor-3-or-6/task.md index 09108484a..2d51b5fe0 100644 --- a/9-regular-expressions/11-regexp-groups/02-find-webcolor-3-or-6/task.md +++ b/9-regular-expressions/11-regexp-groups/02-find-webcolor-3-or-6/task.md @@ -1,8 +1,8 @@ -# Find color in the format #abc or #abcdef +# এই কালার ফরম্যাটগুলো খুঁজুন #abc বা #abcdef -Write a RegExp that matches colors in the format `#abc` or `#abcdef`. That is: `#` followed by 3 or 6 hexadecimal digits. +একটি রেগুলার এক্সপ্রেশন লিখুন যা এই দুটি কালার ফরম্যাটের সাথে ম্যাচ করবে `#abc` বা `#abcdef`। এটি হবে: `#` দ্বারা ৩ বা ৬ অঙ্কের হেক্সাডেসিমেল নাম্বার। -Usage example: +উদাহরণস্বরুপ: ```js let regexp = /your regexp/g; @@ -11,4 +11,4 @@ let str = "color: #3f3; background-color: #AA00ef; and: #abcd"; alert( str.match(regexp) ); // #3f3 #AA00ef ``` -P.S. This should be exactly 3 or 6 hex digits. Values with 4 digits, such as `#abcd`, should not match. +বি.দ্র. এটি অবশ্যই ৩ বা ৬ অঙ্কের হেক্সাডেসিমেল নাম্বার হতে হবে। যেমন, ৪ অঙ্কের সাথে `#abcd` এরা মিলবে না। \ No newline at end of file From f7e94cc8086e99b125f7291f401b6f04da115b28 Mon Sep 17 00:00:00 2001 From: Saiful Date: Wed, 13 Jan 2021 12:20:09 +0600 Subject: [PATCH 6/9] done task-3 --- .../11-regexp-groups/03-find-decimal-numbers/solution.md | 4 ++-- .../11-regexp-groups/03-find-decimal-numbers/task.md | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/9-regular-expressions/11-regexp-groups/03-find-decimal-numbers/solution.md b/9-regular-expressions/11-regexp-groups/03-find-decimal-numbers/solution.md index c4349f9a0..85254c216 100644 --- a/9-regular-expressions/11-regexp-groups/03-find-decimal-numbers/solution.md +++ b/9-regular-expressions/11-regexp-groups/03-find-decimal-numbers/solution.md @@ -1,6 +1,6 @@ -A positive number with an optional decimal part is (per previous task): `pattern:\d+(\.\d+)?`. +আমরা পূর্বের চ্যাপ্টারে ডেসিমেল সংখ্যা কে অপশনাল রেখে খুঁজার উপায় দেখেছিলাম: `pattern:\d+(\.\d+)?`। -Let's add the optional `pattern:-` in the beginning: +ঋণাত্নক সংখ্যা খুঁজার জন্য শুরুতে `pattern:-` কে অপশনাল হিসেবে যোগ করি: ```js run let regexp = /-?\d+(\.\d+)?/g; diff --git a/9-regular-expressions/11-regexp-groups/03-find-decimal-numbers/task.md b/9-regular-expressions/11-regexp-groups/03-find-decimal-numbers/task.md index 4f5a73fff..ea35c0282 100644 --- a/9-regular-expressions/11-regexp-groups/03-find-decimal-numbers/task.md +++ b/9-regular-expressions/11-regexp-groups/03-find-decimal-numbers/task.md @@ -1,8 +1,8 @@ -# Find all numbers +# সকল নাম্বার খুঁজুন -Write a regexp that looks for all decimal numbers including integer ones, with the floating point and negative ones. +সকল ডেসিমেল (পূর্ণ সংখ্যা এবং ঋণাত্নক) সংখ্যা খুঁজার একটি রেগুলার এক্সপ্রেশন লিখুন। -An example of use: +উদাহরণস্বরুপ: ```js let regexp = /your regexp/g; From 4ecd6034cb73c7b93861aeaf950cf752bfa847ac Mon Sep 17 00:00:00 2001 From: Saiful Date: Wed, 13 Jan 2021 12:35:14 +0600 Subject: [PATCH 7/9] translation wip task-4 --- .../04-parse-expression/solution.md | 4 ++-- .../04-parse-expression/task.md | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/9-regular-expressions/11-regexp-groups/04-parse-expression/solution.md b/9-regular-expressions/11-regexp-groups/04-parse-expression/solution.md index 130c57be3..6d819fa1f 100644 --- a/9-regular-expressions/11-regexp-groups/04-parse-expression/solution.md +++ b/9-regular-expressions/11-regexp-groups/04-parse-expression/solution.md @@ -1,6 +1,6 @@ -A regexp for a number is: `pattern:-?\d+(\.\d+)?`. We created it in previous tasks. +সংখ্যা খুঁজার রেগুলার এক্সপ্রেশন: `pattern:-?\d+(\.\d+)?`। যা আমরা পূর্বের টাস্কে করেছিলাম। -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 `-`. +অপারেটর হল `pattern:[-+*/]`. হাইফেন `pattern:-` অবশ্যই ব্রাকেটের শুরুতে হতে হবে, কেননা মাঝে হলে এটি দ্বারা ক্যারাক্টারের রেঞ্জ বুঝায়, যেখানে আমরা `-` কে ক্যারাক্টার হিসেবে দেখতে চায়। The slash `/` should be escaped inside a JavaScript regexp `pattern:/.../`, we'll do that later. diff --git a/9-regular-expressions/11-regexp-groups/04-parse-expression/task.md b/9-regular-expressions/11-regexp-groups/04-parse-expression/task.md index 8b54d4683..7e45e5585 100644 --- a/9-regular-expressions/11-regexp-groups/04-parse-expression/task.md +++ b/9-regular-expressions/11-regexp-groups/04-parse-expression/task.md @@ -1,23 +1,23 @@ -# Parse an expression +# এক্সপ্রেশনকে পার্স -An arithmetical expression consists of 2 numbers and an operator between them, for instance: +একটি গাণিতিক সমীকরণে দুটি নাম্বার এবং তাদের মাঝে একটি গাণিতিক চিহ্ন আছে, যেমন: - `1 + 2` - `1.2 * 3.4` - `-3 / -6` - `-2 - 2` -The operator is one of: `"+"`, `"-"`, `"*"` or `"/"`. +গাণিতিক চিহ্নগুলো হল: `"+"`, `"-"`, `"*"` অথবা `"/"`। -There may be extra spaces at the beginning, at the end or between the parts. +এখানে সমীকরণের শুরুতে,মাঝে এবং শেষে অতিরিক্ত স্পেস থাকতে পারে। -Create a function `parse(expr)` that takes an expression and returns an array of 3 items: +একটি ফাংশন লিখুন যা `parse(expr)` একটি সমীকরণ নিবে এবং তাদের কে একটি অ্যারের ৩ টি উপাদান হিসেবে রিটার্ন করবে: -1. The first number. -2. The operator. -3. The second number. +১. প্রথম সংখ্যাটি। +২. গাণিতিক চিহ্নটি। +৩. দ্বিতীয় সংখ্যাটি। -For example: +যেমন: ```js let [a, op, b] = parse("1.2 * 3.4"); From 9bbbe1c4d56ee29417daf4999ce0228c2963ac33 Mon Sep 17 00:00:00 2001 From: Saiful Date: Wed, 13 Jan 2021 14:16:26 +0600 Subject: [PATCH 8/9] done task-4 --- .../04-parse-expression/solution.md | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/9-regular-expressions/11-regexp-groups/04-parse-expression/solution.md b/9-regular-expressions/11-regexp-groups/04-parse-expression/solution.md index 6d819fa1f..7f993ff15 100644 --- a/9-regular-expressions/11-regexp-groups/04-parse-expression/solution.md +++ b/9-regular-expressions/11-regexp-groups/04-parse-expression/solution.md @@ -1,21 +1,22 @@ সংখ্যা খুঁজার রেগুলার এক্সপ্রেশন: `pattern:-?\d+(\.\d+)?`। যা আমরা পূর্বের টাস্কে করেছিলাম। -অপারেটর হল `pattern:[-+*/]`. হাইফেন `pattern:-` অবশ্যই ব্রাকেটের শুরুতে হতে হবে, কেননা মাঝে হলে এটি দ্বারা ক্যারাক্টারের রেঞ্জ বুঝায়, যেখানে আমরা `-` কে ক্যারাক্টার হিসেবে দেখতে চায়। +অপারেটর হল `pattern:[-+*/]`. হাইফেন `pattern:-` অবশ্যই ব্রাকেটের শুরুতে হতে হবে, কেননা মাঝে হলে এটি দ্বারা ক্যারাক্টারের রেঞ্জ বুঝায়, এখানে আমরা `-` কে ক্যারাক্টার হিসেবে ব্যবহার করতে চায়। -The slash `/` should be escaped inside a JavaScript regexp `pattern:/.../`, we'll do that later. +স্ল্যাশ `/` অবশ্যই জাভাস্ক্রিপ্টের রেগুলার এক্সপ্রেশনের মাঝে এস্কেপড `pattern:/.../` হয়, এটি আমরা এটি পরে দেখব। -We need a number, an operator, and then another number. And optional spaces between them. +আমাদের খুঁজা লাগবে একটি সংখ্যা অতঃপর একটি গাণিতিক চিহ্ন এবং শেষে আরো একটি সংখ্যা এবং তাদের মাঝের অতিরিক্ত স্পেস। -The full regular expression: `pattern:-?\d+(\.\d+)?\s*[-+*/]\s*-?\d+(\.\d+)?`. -It has 3 parts, with `pattern:\s*` between them: -1. `pattern:-?\d+(\.\d+)?` - the first number, -1. `pattern:[-+*/]` - the operator, -1. `pattern:-?\d+(\.\d+)?` - the second number. +সুতরাং রেগুলার এক্সপ্রেশনটি হবে: `pattern:-?\d+(\.\d+)?\s*[-+*/]\s*-?\d+(\.\d+)?`। -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+)?)`. +এর ৩টি অংশ আছে, সাথে এটিও `pattern:\s*`: +১. `pattern:-?\d+(\.\d+)?` - প্রথম সংখ্যাটি। +২. `pattern:[-+*/]` - গাণিতিক চিহ্নটি। +৩. `pattern:-?\d+(\.\d+)?` - দ্বিতীয় সংখ্যাটি। -In action: +তাদের প্রত্যেককে রেজাল্ট অ্যারের আলাদা আলাদা উপাদান হিসেবে রাখতে প্যারান্টেসিস দ্বারা গ্রুপ করি: `pattern:(-?\d+(\.\d+)?)\s*([-+*/])\s*(-?\d+(\.\d+)?)`। + +যেমন: ```js run let regexp = /(-?\d+(\.\d+)?)\s*([-+*\/])\s*(-?\d+(\.\d+)?)/; @@ -23,22 +24,22 @@ let regexp = /(-?\d+(\.\d+)?)\s*([-+*\/])\s*(-?\d+(\.\d+)?)/; alert( "1.2 + 12".match(regexp) ); ``` -The result includes: +রেজাল্টে: -- `result[0] == "1.2 + 12"` (full match) -- `result[1] == "1.2"` (first group `(-?\d+(\.\d+)?)` -- the first number, including the decimal part) -- `result[2] == ".2"` (second group`(\.\d+)?` -- the first decimal part) -- `result[3] == "+"` (third group `([-+*\/])` -- the operator) -- `result[4] == "12"` (forth group `(-?\d+(\.\d+)?)` -- the second number) -- `result[5] == undefined` (fifth group `(\.\d+)?` -- the last decimal part is absent, so it's undefined) +- `result[0] == "1.2 + 12"` (সম্পূর্ন এক্সপ্রেশনটি) +- `result[1] == "1.2"` (প্রথম গ্রুপ `(-?\d+(\.\d+)?)` -- প্রথম সংখ্যাটি, দশমিক অংশটিসহ) +- `result[2] == ".2"` (দ্বিতীয় গ্রুপ`(\.\d+)?` -- প্রথম দশমিক অংশটি) +- `result[3] == "+"` (তৃতীয় গ্রুপ `([-+*\/])` -- গাণিতিক চিহ্নটি) +- `result[4] == "12"` (চতুর্থ গ্রুপ `(-?\d+(\.\d+)?)` -- দ্বিতীয় সংখ্যাটি) +- `result[5] == undefined` (পঞ্চম গ্রুপ `(\.\d+)?` -- দ্বিতীয় দশমিক অংশটি অনুপস্থিত, সুতরাং এটি undefined) -We only want the numbers and the operator, without the full match or the decimal parts, so let's "clean" the result a bit. +আমরা শুধু সংখ্যাগুলো এবং গাণিতিক চিহ্নটি চায়, সম্পূর্ন অংশটি বা দশমিক অংশটি চায় না, সুতরাং আমাদের রেজাল্টকে আরো কিছুটা "clean" করি। -The full match (the arrays first item) can be removed by shifting the array `result.shift()`. +সম্পূর্ন অংশটি যা অ্যারের প্রথম ইলিমেন্ট একে আমরা `result.shift()` মেথডের সাহায্যে বাদ দিতে পারি। -Groups that contain decimal parts (number 2 and 4) `pattern:(.\d+)` can be excluded by adding `pattern:?:` to the beginning: `pattern:(?:\.\d+)?`. +যে গ্রুপগুলোতে দশমিক অংশ থাকে (২ এবং ৪ আইটেম) এই অংশের `pattern:(.\d+)` শুরুতে `pattern:?:` যোগ করে তাদের বাদ দিতে পারি: `pattern:(?:\.\d+)?`। -The final solution: +সুতরাং সমাধানটি হবে: ```js run function parse(expr) { From e4a00bc8b27763be809df0b45fd6579fd16672b2 Mon Sep 17 00:00:00 2001 From: Saiful Date: Wed, 13 Jan 2021 14:18:23 +0600 Subject: [PATCH 9/9] little bit translate --- 9-regular-expressions/11-regexp-groups/01-test-mac/task.md | 2 +- .../11-regexp-groups/02-find-webcolor-3-or-6/task.md | 2 +- .../11-regexp-groups/03-find-decimal-numbers/task.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/9-regular-expressions/11-regexp-groups/01-test-mac/task.md b/9-regular-expressions/11-regexp-groups/01-test-mac/task.md index 5d4bf9cc2..b36bf69f3 100644 --- a/9-regular-expressions/11-regexp-groups/01-test-mac/task.md +++ b/9-regular-expressions/11-regexp-groups/01-test-mac/task.md @@ -8,7 +8,7 @@ MAC-address যাচাইয়ের জন্য একটি রেগুল উদাহরণস্বরুপ: ```js -let regexp = /your regexp/; +let regexp = /আপনার প্যাটার্ন লিখুন/; alert( regexp.test('01:32:54:67:89:AB') ); // সত্য diff --git a/9-regular-expressions/11-regexp-groups/02-find-webcolor-3-or-6/task.md b/9-regular-expressions/11-regexp-groups/02-find-webcolor-3-or-6/task.md index 2d51b5fe0..7203ea33a 100644 --- a/9-regular-expressions/11-regexp-groups/02-find-webcolor-3-or-6/task.md +++ b/9-regular-expressions/11-regexp-groups/02-find-webcolor-3-or-6/task.md @@ -4,7 +4,7 @@ উদাহরণস্বরুপ: ```js -let regexp = /your regexp/g; +let regexp = /আপনার প্যাটার্ন লিখুন/g; let str = "color: #3f3; background-color: #AA00ef; and: #abcd"; diff --git a/9-regular-expressions/11-regexp-groups/03-find-decimal-numbers/task.md b/9-regular-expressions/11-regexp-groups/03-find-decimal-numbers/task.md index ea35c0282..6f4f3fcdb 100644 --- a/9-regular-expressions/11-regexp-groups/03-find-decimal-numbers/task.md +++ b/9-regular-expressions/11-regexp-groups/03-find-decimal-numbers/task.md @@ -5,7 +5,7 @@ উদাহরণস্বরুপ: ```js -let regexp = /your regexp/g; +let regexp = /আপনার প্যাটার্ন লিখুন/g; let str = "-1.5 0 2 -123.4.";