Skip to content

Commit 7611bcb

Browse files
authored
Merge pull request #198 from msisaifu/regexp-quantifiers
Quantifiers +, *, ? and {n}
2 parents 3ffb636 + 6aa6ba4 commit 7611bcb

File tree

5 files changed

+64
-64
lines changed

5 files changed

+64
-64
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

2-
Solution:
2+
সমাধান:
33

44
```js run
55
let regexp = /\.{3,}/g;
66
alert( "Hello!... How goes?.....".match(regexp) ); // ..., .....
77
```
88

9-
Please note that the dot is a special character, so we have to escape it and insert as `\.`.
9+
আমাদের মনে রাখা উচিত ডট একটি স্পেশাল ক্যারাক্টার, সুতরাং এটিকে আমাদের ব্যাকস্লাশের `\.` মাধ্যমে এস্কেপিং করে নিতে হবে।
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
importance: 5
1+
গুরুত্বপূর্ন: ৫
22

33
---
44

5-
# How to find an ellipsis "..." ?
5+
# কিভাবে একটি উপবৃত্ত খুঁজে পাব "..." ?
66

7-
Create a regexp to find ellipsis: 3 (or more?) dots in a row.
7+
একটি রেগুলার এক্সপ্রেশন লিখুন যা: ৩ (অথবা ততোধিক?) ডটের উপবৃত্ত খুঁজবে।
88

9-
Check it:
9+
এটি দেখুন:
1010

1111
```js
12-
let regexp = /your regexp/g;
12+
let regexp = /আপনার রেগুলার এক্সপ্রেশনটি লিখুন/g;
1313
alert( "Hello!... How goes?.....".match(regexp) ); // ..., .....
1414
```
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
We need to look for `#` followed by 6 hexadecimal characters.
1+
আমাদের `#` এর পর ৬টি হেক্সাডেসিমেল ক্যারাক্টার খোঁজা লাগবে।
22

3-
A hexadecimal character can be described as `pattern:[0-9a-fA-F]`. Or if we use the `pattern:i` flag, then just `pattern:[0-9a-f]`.
3+
`pattern:[0-9a-fA-F]` এর মাধ্যমে আমরা হেক্সাডেসিমেল ক্যারাক্টার সংজ্ঞায়িত করতে পারি। অথবা যদি আমরা `pattern:i` ফ্ল্যাগ ব্যবহার করি তাহলে প্যাটার্নটি হবে `pattern:[0-9a-f]`
44

5-
Then we can look for 6 of them using the quantifier `pattern:{6}`.
5+
এখন আমরা কোয়ান্টিফায়ার `pattern:{6}` ব্যবহার করে ৬টি ক্যারাক্টার খুঁজতে পারি।
66

7-
As a result, we have the regexp: `pattern:/#[a-f0-9]{6}/gi`.
7+
ফলস্বরূপ, রেগুলার এক্সপ্রেশনটি হবে: `pattern:/#[a-f0-9]{6}/gi`
88

99
```js run
1010
let regexp = /#[a-f0-9]{6}/gi;
@@ -14,18 +14,18 @@ let str = "color:#121212; background-color:#AA00ef bad-colors:f#fddee #fd2"
1414
alert( str.match(regexp) ); // #121212,#AA00ef
1515
```
1616

17-
The problem is that it finds the color in longer sequences:
17+
তবে এর সমস্যা হল দীর্ঘতম সিক্যুয়েন্সেও এটি কালার খুঁজবে:
1818

1919
```js run
2020
alert( "#12345678".match( /#[a-f0-9]{6}/gi ) ) // #123456
2121
```
2222

23-
To fix that, we can add `pattern:\b` to the end:
23+
শেষে `pattern:\b` সংযোজন করে আমরা এটি সমাধান করতে পারি:
2424

2525
```js run
26-
// color
26+
// সঠিক কালার কোড
2727
alert( "#123456".match( /#[a-f0-9]{6}\b/gi ) ); // #123456
2828

29-
// not a color
29+
// ভুল কালার কোড
3030
alert( "#12345678".match( /#[a-f0-9]{6}\b/gi ) ); // null
3131
```
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
# Regexp for HTML colors
1+
# এইচটিএমএল কালারের জন্য রেগুলার এক্সপ্রেশন
22

3-
Create a regexp to search HTML-colors written as `#ABCDEF`: first `#` and then 6 hexadecimal characters.
3+
হেক্সাডেসিমেল এইচটিএমএল কালার `#ABCDEF`: প্রথমে `#` তারপর ৬ টি হেক্সাডেসিমেল ক্যারাক্টার খোঁজার জন্য একটি রেগুলার এক্সপ্রেশন লিখুন।
44

5-
An example of use:
5+
ব্যবহারযোগ্য একটি উদাহরণ:
66

77
```js
8-
let regexp = /...your regexp.../
8+
let regexp = /...আপনার রেগুলার এক্সপ্রেশনটি লিখুন.../
99

1010
let str = "color:#121212; background-color:#AA00ef bad-colors:f#fddee #fd2 #12345678";
1111

1212
alert( str.match(regexp) ) // #121212,#AA00ef
1313
```
1414

15-
P.S. In this task we do not need other color formats like `#123` or `rgb(1,2,3)` etc.
15+
পুনশ্চ এই টাস্কে আমাদের `#123` বা `rgb(1,2,3)` ইত্যাদি কালার ফরমেটগুলোর প্রয়োজন নেই।
+44-44
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
1-
# Quantifiers +, *, ? and {n}
1+
# কোয়ান্টিফায়ার +, *, ? এবং {n}
22

3-
Let's say we have a string like `+7(903)-123-45-67` and want to find all numbers in it. But unlike before, we are interested not in single digits, but full numbers: `7, 903, 123, 45, 67`.
3+
এখন মনে করন আমাদের এমন একটি `+7(903)-123-45-67` স্ট্রিং আছে এবং আমরা এর সকল নাম্বার খুঁজে পেতে চাই। কিন্ত পূর্বের মত, আমরা একক অঙ্ক চাই না, পূর্ণ সংখ্যাগুলো চাই: `7, 903, 123, 45, 67`
44

5-
A number is a sequence of 1 or more digits `pattern:\d`. To mark how many we need, we can append a *quantifier*.
5+
সংখ্যা হল এক বা একাধিক অঙ্কের একটি সমষ্টি `pattern:\d`। আমাদের প্রয়োজনমত অঙ্কের জন্য আমরা *quantifier* সংযোজন করতে পারি।
66

7-
## Quantity {n}
7+
## সংখ্যা {n}
88

9-
The simplest quantifier is a number in curly braces: `pattern:{n}`.
9+
সবচেয়ে সহজ কোয়ান্টিফায়ার হল দ্বিতীয় বন্ধনীর মধ্যে একটি সংখ্যা: `pattern:{n}`
1010

11-
A quantifier is appended to a character (or a character class, or a `[...]` set etc) and specifies how many we need.
11+
কোয়ান্টিফায়ারে যেকোন ধরণের ক্যারাক্টার (অথবা ক্যারাক্টার ক্লাস, অথবা `[...]` সেট ইত্যাদি) আমাদের প্রয়োজনমত সংযোজন করতে পারি।
1212

13-
It has a few advanced forms, let's see examples:
13+
এটি ব্যবহারের বিভিন্ন উপায় আছে, চলুন কয়েকটি উদাহরণ দেখি:
1414

15-
The exact count: `pattern:{5}`
16-
: `pattern:\d{5}` denotes exactly 5 digits, the same as `pattern:\d\d\d\d\d`.
15+
নির্দিষ্ট সংখ্যা গণনা: `pattern:{5}`
16+
: `pattern:\d{5}` এটি দ্বারা ৫টি অঙ্ক বুঝায়, যা `pattern:\d\d\d\d\d` এর অনুরূপ।
1717

18-
The example below looks for a 5-digit number:
18+
নিচের উদাহরণে একটি ৫ অঙ্কের সংখ্যা খোঁজা হচ্ছে:
1919

2020
```js run
2121
alert( "I'm 12345 years old".match(/\d{5}/) ); // "12345"
2222
```
2323

24-
We can add `\b` to exclude longer numbers: `pattern:\b\d{5}\b`.
24+
আমরা `\b` যুক্ত করে এর চেয়ে বড় অঙ্কের সংখ্যাগুলো বাদ দিতে পারি: `pattern:\b\d{5}\b`
2525

26-
The range: `pattern:{3,5}`, match 3-5 times
27-
: To find numbers from 3 to 5 digits we can put the limits into curly braces: `pattern:\d{3,5}`
26+
রেঞ্জ: `pattern:{3,5}`, ৩-৫ অঙ্কের সংখ্যার সাথে মিল খুঁজে
27+
: ৩ থেকে ৫ অঙ্কের মধ্যের সংখ্যা গুলো খুঁজতে আমরা দ্বিতীয় বন্ধনীতে সীমা নির্ধারণ করে দিতে পারি: `pattern:\d{3,5}`
2828

2929
```js run
3030
alert( "I'm not 12, but 1234 years old".match(/\d{3,5}/) ); // "1234"
3131
```
3232

33-
We can omit the upper limit.
33+
আমরা সর্বোচ্চ সীমাটি বাদ দিতে পারি।
3434

35-
Then a regexp `pattern:\d{3,}` looks for sequences of digits of length `3` or more:
35+
এ রেগুলার এক্সপ্রেশনটি `pattern:\d{3,}` ৩ বা ততোধিক অঙ্কের মিল গুলো খোঁজে:
3636

3737
```js run
3838
alert( "I'm not 12, but 345678 years old".match(/\d{3,}/) ); // "345678"
3939
```
4040

41-
Let's return to the string `+7(903)-123-45-67`.
41+
এখন আমাদের পূর্বের `+7(903)-123-45-67` স্ট্রিংটি দেখি।
4242

43-
A number is a sequence of one or more digits in a row. So the regexp is `pattern:\d{1,}`:
43+
সংখ্যা হল এক বা একাধিক অঙ্কের সমষ্টি। সুতরাং রেগুলার এক্সপ্রেশনটি হবে `pattern:\d{1,}`:
4444

4545
```js run
4646
let str = "+7(903)-123-45-67";
@@ -50,14 +50,14 @@ let numbers = str.match(/\d{1,}/g);
5050
alert(numbers); // 7,903,123,45,67
5151
```
5252

53-
## Shorthands
53+
## সংক্ষিপ্তরূপ
5454

55-
There are shorthands for most used quantifiers:
55+
কোয়ান্টিফায়ারের কিছু সংক্ষিপ্তরূপ আছে:
5656

5757
`pattern:+`
58-
: Means "one or more", the same as `pattern:{1,}`.
58+
: এটি দ্বারা বুঝায় "এক বা ততোধিক", এটি `pattern:{1,}` এর অনুরূপ।
5959

60-
For instance, `pattern:\d+` looks for numbers:
60+
উদাহরণস্বরূপ, `pattern:\d+` প্যাটার্নটি দ্বারা সংখ্যা খোঁজা হয়:
6161

6262
```js run
6363
let str = "+7(903)-123-45-67";
@@ -66,11 +66,11 @@ There are shorthands for most used quantifiers:
6666
```
6767

6868
`pattern:?`
69-
: Means "zero or one", the same as `pattern:{0,1}`. In other words, it makes the symbol optional.
69+
: এটি দ্বারা বুঝায় "শূন্য বা এক", এটি `pattern:{0,1}` এর অনুরূপ। অন্যথায় বলা যায়, এটি ঐচ্ছিক কোয়ান্টিফায়ার।
7070

71-
For instance, the pattern `pattern:ou?r` looks for `match:o` followed by zero or one `match:u`, and then `match:r`.
71+
উদাহরণস্বরূপ, `pattern:ou?r` প্যাটার্নটি `match:o` এর পর শূন্য বা একটি `match:u` এর খুঁজ করে, এবং তারপর `match:r` এর সাথে মিল খুঁজে।
7272

73-
So, `pattern:colou?r` finds both `match:color` and `match:colour`:
73+
সুতরাং, `pattern:colou?r` প্যাটার্নটি দ্বারা `match:color` এবং `match:colour` উভয়ের সাথে মিল হবে:
7474

7575
```js run
7676
let str = "Should I write color or colour?";
@@ -79,64 +79,64 @@ There are shorthands for most used quantifiers:
7979
```
8080

8181
`pattern:*`
82-
: Means "zero or more", the same as `pattern:{0,}`. That is, the character may repeat any times or be absent.
82+
: এটি দ্বারা বুঝায় "শূন্য বা ততোধিক", এটি `pattern:{0,}` এর অনুরূপ। অন্যথায় বলা যায়, ক্যারাক্টারটি একাধিকও থাকতে পারে অথবা নাও থাকতে পারে।
8383

84-
For example, `pattern:\d0*` looks for a digit followed by any number of zeroes (may be many or none):
84+
উদাহরণস্বরূপ, `pattern:\d0*` প্যাটার্নটি দ্বারা শূন্যের খুঁজ করে (একাধিকও থাকতে পারে অথবা নাও থাকতে পারে):
8585

8686
```js run
8787
alert( "100 10 1".match(/\d0*/g) ); // 100, 10, 1
8888
```
8989

90-
Compare it with `pattern:+` (one or more):
90+
চলুন একে `pattern:+` এর সাথে তুলনা করে দেখি (এক বা ততোধিক):
9191

9292
```js run
9393
alert( "100 10 1".match(/\d0+/g) ); // 100, 10
94-
// 1 not matched, as 0+ requires at least one zero
94+
// 1 এর সাথে মিল পায়নি, যেহেতু 0+ দ্বারা অন্তত একটি শূন্য থাকতে হবে বুঝায়
9595
```
9696

97-
## More examples
97+
## আরো কিছু উদাহরণ
9898

99-
Quantifiers are used very often. They serve as the main "building block" of complex regular expressions, so let's see more examples.
99+
রেগুলার এক্সপ্রেশনে আমরা প্রায় কোয়ান্টিফায়ার ব্যবহার করি। এরা জটিল রেগুলার এক্সপ্রেশনে প্রধান "বিল্ডিং ব্লক" হিসেবে কাজ করে, চলুন কিছু উদাহরণ দেখি।
100100

101-
**Regexp for decimal fractions (a number with a floating point): `pattern:\d+\.\d+`**
101+
**দশমিক ভগ্নাংশের জন্য রেগুলার এক্সপ্রেশন (দশমিক সহ সংখ্যা): `pattern:\d+\.\d+`**
102102

103-
In action:
103+
এটি দেখুন:
104104
```js run
105105
alert( "0 1 12.345 7890".match(/\d+\.\d+/g) ); // 12.345
106106
```
107107

108-
**Regexp for an "opening HTML-tag without attributes", such as `<span>` or `<p>`.**
108+
**"অ্যাট্রিবিউট ছাড়া শুরুর এইচটিএমএল ট্যাগ" এর জন্য রেগুলার এক্সপ্রেশন, যেমন `<span>` অথবা `<p>`.**
109109

110-
1. The simplest one: `pattern:/<[a-z]+>/i`
110+
1. সাধারণ এই প্যাটার্নটি দেখুন: `pattern:/<[a-z]+>/i`
111111

112112
```js run
113113
alert( "<body> ... </body>".match(/<[a-z]+>/gi) ); // <body>
114114
```
115115

116-
The regexp looks for character `pattern:'<'` followed by one or more Latin letters, and then `pattern:'>'`.
116+
রেগুলার এক্সপ্রেশনটি প্রথমে `pattern:'<'` এর সাথে মিলে তারপর এক বা একাধিক লাতিন বর্ণের সাথে মিলে শেষে `pattern:'>'` এর সাথে মিলে।
117117

118-
2. Improved: `pattern:/<[a-z][a-z0-9]*>/i`
118+
2. উন্নত এই প্যাটার্নটি দেখুন: `pattern:/<[a-z][a-z0-9]*>/i`
119119

120-
According to the standard, HTML tag name may have a digit at any position except the first one, like `<h1>`.
120+
স্ট্যান্ডার্ড নামানুসারে, এইচটিএমএল ট্যাগে প্রথম ক্যারাক্টারটি বাদে যেকোন পজিশনে অঙ্ক থাকতে পারে, যেমন `<h1>`
121121

122122
```js run
123123
alert( "<h1>Hi!</h1>".match(/<[a-z][a-z0-9]*>/gi) ); // <h1>
124124
```
125125

126-
**Regexp "opening or closing HTML-tag without attributes": `pattern:/<\/?[a-z][a-z0-9]*>/i`**
126+
**"অ্যাট্রিবিউট ছাড়া শুরুর এবং শেষের এইচটিএমএল ট্যাগ" এর জন্য রেগুলার এক্সপ্রেশন: `pattern:/<\/?[a-z][a-z0-9]*>/i`**
127127

128-
We added an optional slash `pattern:/?` near the beginning of the pattern. Had to escape it with a backslash, otherwise JavaScript would think it is the pattern end.
128+
আমরা প্যাটার্নের শুরুতে একটি ঐচ্ছিক স্লাশ `pattern:/?` দিয়ে শুরু করেছি। এটি ব্যাকস্লাশ দিয়ে বাদ দিতে হবে, অন্যথায় জাভাস্ক্রিপ্ট ইঞ্জিন প্যাটার্ন শেষ হিসেবে ধরে নিবে।
129129

130130
```js run
131131
alert( "<h1>Hi!</h1>".match(/<\/?[a-z][a-z0-9]*>/gi) ); // <h1>, </h1>
132132
```
133133

134-
```smart header="To make a regexp more precise, we often need make it more complex"
135-
We can see one common rule in these examples: the more precise is the regular expression -- the longer and more complex it is.
134+
```smart header="একটি রেগুলার এক্সপ্রেশন কে যথাযথ ব্যবহার করতে, আমরা প্রায় এটিকে জটিল করে তৈরি করি"
135+
আমরা এই উদাহরণগুলোতে একটি সাধারন নিয়ম দেখতে পারছি: রেগুলার এক্সপ্রেশনটি আরো সুনির্দিষ্ট হচ্ছে -- দীর্ঘতর এবং আরো জটিল হচ্ছে।
136136
137-
For instance, for HTML tags we could use a simpler regexp: `pattern:<\w+>`. But as HTML has stricter restrictions for a tag name, `pattern:<[a-z][a-z0-9]*>` is more reliable.
137+
উদাহরণস্বরূপ, এইচটিএমএল ট্যাগের জন্য আমরা সহজ এই রেগুলার এক্সপ্রেশনটি: `pattern:<\w+>` ব্যবহার করতে পারি। কিন্তু এইচটিএমএল ট্যাগের নামানুসারে আমরা এই `pattern:<[a-z][a-z0-9]*>` প্যাটার্নটি আরো পঠনযোগ্য করতে পারি।
138138
139-
Can we use `pattern:<\w+>` or we need `pattern:<[a-z][a-z0-9]*>`?
139+
আমরা কি এটি `pattern:<\w+>` অথবা এটি `pattern:<[a-z][a-z0-9]*>` ব্যবহার করতে পারি?
140140
141-
In real life both variants are acceptable. Depends on how tolerant we can be to "extra" matches and whether it's difficult or not to remove them from the result by other means.
141+
বাস্তবক্ষেত্রে দুটিই ব্যবহারযোগ্য। এটি নির্ভর করে আমরা কিভাবে "অতিরিক্ত" মিলগুলো ব্যবহার করব এবং অন্যান্য ক্ষেত্রে মিল গুলো থেকে কিভাবে তাদের বাদ দিব তার উপর নির্ভর করে।
142142
```

0 commit comments

Comments
 (0)