You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Regular expressions are patterns that provide a powerful way to search and replace in text.
3
+
টেক্সটে কোনকিছু খোঁজা অথবা রিপ্লেস করার একটি পাওয়ারফুল মাধ্যম হল রেগুলার এক্সপ্রেশন।
4
4
5
-
In JavaScript, they are available via the [RegExp](mdn:js/RegExp)object, as well as being integrated in methods of strings.
5
+
জাভাস্ক্রীপ্টে এটি [RegExp](mdn:js/RegExp)অবজেক্টের অধীনে আছে এবং স্ট্রিং এর মেথডগুলোর মধ্যে এদের ব্যবহার করতে পারি।
6
6
7
-
## Regular Expressions
7
+
## রেগুলার এক্সপ্রেশনস
8
8
9
-
A regular expression (also "regexp", or just "reg") consists of a *pattern* and optional *flags*.
9
+
রেগুলার এক্সপ্রেশন (যা "regexp" অথবা "reg" নামেও পরিচিত) হল *প্যাটার্ন* এবং অপশনাল *ফ্ল্যাগ* এর মাধ্যমে গঠিত একটি সমন্বিতরূপ।
10
10
11
-
There are two syntaxes that can be used to create a regular expression object.
11
+
দুইভাবে আমরা রেগুলার এক্সপ্রেশন অবজেক্ট তৈরি করতে পারি।
12
12
13
-
The "long" syntax:
13
+
"লং" সিনট্যাক্সঃ
14
14
15
15
```js
16
-
regexp =newRegExp("pattern", "flags");
16
+
regexp =newRegExp("প্যাটার্ন", "ফ্ল্যাগ");
17
17
```
18
18
19
-
And the "short" one, using slashes `"/"`:
19
+
এবং "শর্ট" সিনট্যাক্স যা `"/"` দ্বারা ডিক্লেয়ার করা হয়ঃ
20
20
21
21
```js
22
-
regexp =/pattern/; //no flags
23
-
regexp =/pattern/gmi; //with flags g,m and i (to be covered soon)
22
+
regexp =/pattern/; //ফ্ল্যাগ ছাড়া
23
+
regexp =/pattern/gmi; //ফ্ল্যাগ সহ g,m and i (এগুলো সম্পর্কে সামনেই জানতে পারব)
24
24
```
25
25
26
-
Slashes`pattern:/.../`tell JavaScript that we are creating a regular expression. They play the same role as quotes for strings.
26
+
স্ল্যাস`pattern:/.../`ব্যবহারের মাধ্যমে জাভাস্ক্রীপ্ট ইঞ্জিন বুঝতে পারে এটি একটি রেগুলার এক্সপ্রেশন। যেভাবে `""` অথবা `''` দ্বারা স্ট্রীং কে চিনতে পারে।
27
27
28
-
In both cases `regexp`becomes an instance of the built-in `RegExp` class.
28
+
উভয়ক্ষেত্রে `regexp`বিল্টইন `RegExp` ক্লাস এর ইনস্ট্যান্স হিসেবে তৈরি হয়।
29
29
30
-
The main difference between these two syntaxes is that pattern using slashes `/.../`does not allow for expressions to be inserted (like string template literals with `${...}`). They are fully static.
30
+
এই দুই সিনট্যাক্সের মূল পার্থক্য হল `/.../`এখানে ডাইনামিক্যালি কোন ভেরিয়েবল (যেমনঃ টেমপ্লেট লিটারেলস স্ট্রিং `${...}`) ব্যবহার করতে পারবেন না। এটি পুরোপুরি স্ট্যাটিক।
31
31
32
32
Slashes are used when we know the regular expression at the code writing time -- and that's the most common situation. While `new RegExp`, is more often used when we need to create a regexp "on the fly" from a dynamically generated string. For instance:
33
33
34
34
```js
35
-
let tag =prompt("What tag do you want to find?", "h2");
35
+
let tag =prompt("আপনি কোন ট্যাগটি খুঁজতে চাচ্ছেন?", "h2");
36
36
37
-
let regexp =newRegExp(`<${tag}>`); //same as /<h2>/ if answered "h2" in the prompt above
37
+
let regexp =newRegExp(`<${tag}>`); //এটি /<h2>/ এর মত যদি prompt এ ইনপুট h2 দেয়
38
38
```
39
39
40
-
## Flags
40
+
## ফ্ল্যাগ
41
41
42
-
Regular expressions may have flags that affect the search.
42
+
রেগুলার এক্সপ্রেশনে কিছু ফ্ল্যাগ আছে যা সার্চিং এর সময় ব্যবহৃত হয়।
43
43
44
-
There are only 6 of them in JavaScript:
44
+
জাভাস্ক্রিপ্টে ৬ ধরনের ফ্ল্যাগ আছেঃ
45
45
46
46
`pattern:i`
47
-
: With this flag the search is case-insensitive: no difference between `A`and`a`(see the example below).
47
+
: এই ফ্ল্যাগটি কেস ইনসেনসিটিভ বুঝায়ঃ `A`এবং`a`এর মধ্যে কোন পার্থক্য নেই (নিচের উদাহরণ দেখুন)।
48
48
49
49
`pattern:g`
50
-
: With this flag the search looks for all matches, without it -- only the first match is returned.
50
+
: এই ফ্ল্যাগটি টেক্সটে সব মিল খুঁজে, এটি ছাড়া -- শুধু প্রথম মিলটি রিটার্ন করে।
51
51
52
52
`pattern:m`
53
-
: Multiline mode (covered in the chapter <info:regexp-multiline-mode>).
53
+
: মাল্টিলাইন মোড (বিস্তারিত এই অধ্যায়ে <info:regexp-multiline-mode>)।
54
54
55
55
`pattern:s`
56
-
: Enables "dotall" mode, that allows a dot `pattern:.`to match newline character `\n` (covered in the chapter<info:regexp-character-classes>).
56
+
: "dotall" মোড, নিউলাইন ক্যারেক্টার `\n` কে ডট `pattern:.`দিয়ে খোঁজা যায় (বিস্তারিত এই অধ্যায়ে<info:regexp-character-classes>).
57
57
58
58
`pattern:u`
59
-
: Enables full unicode support. The flag enables correct processing of surrogate pairs. More about that in the chapter <info:regexp-unicode>.
59
+
: ফুল ইউনিকোর্ড সাপোর্ট এনাবল করে। ফ্ল্যাগটি সঠিকভাবে সারোগেটজোড় কে প্রসেসিংয়ের সাপোর্ট দেয়। আরো জানতে পারবেন এই অধ্যায়ে <info:regexp-unicode>।
60
60
61
61
`pattern:y`
62
-
: "Sticky" mode: searching at the exact position in the text (covered in the chapter<info:regexp-sticky>)
62
+
: "Sticky" মোডঃ searching at the exact position in the text (বিস্তারিত এই অধ্যায়ে<info:regexp-sticky>)
63
63
64
-
```smart header="Colors"
64
+
```smart header="কালারস"
65
65
From here on the color scheme is:
66
66
67
67
- regexp -- `pattern:red`
68
68
- string (where we search) -- `subject:blue`
69
69
- result -- `match:green`
70
70
```
71
71
72
-
## Searching: str.match
72
+
## সার্চিংঃ str.match
73
73
74
-
As mentioned previously, regular expressions are integrated with string methods.
74
+
আমরা পূর্বেই জেনেছি, রেগুলার এক্সপ্রেশনগুলো স্ট্রিংয়ের মেথডগুলোর সাথে ইন্টিগ্রেটেড।
75
75
76
-
The method `str.match(regexp)`finds all matches of `regexp`in the string `str`.
76
+
`str.match(regexp)`মেথডটির সাহায্যে `str` এর মধ্যে `regexp`এর সকল মিল খুঁজা যায়।
77
77
78
-
It has 3 working modes:
78
+
এটির ৩ ধরণের মোড আছেঃ
79
79
80
-
1.If the regular expression has flag `pattern:g`, it returns an array of all matches:
80
+
1.যদি রেগুলার এক্সপ্রেশনে `pattern:g` এই ফ্ল্যাগটি ব্যবহৃত হয়, এটি সব মিলপ্রাপ্ত প্যাটার্নগুলোকে অ্যারেতে রিটার্ন করেঃ
81
81
```js run
82
82
let str ="We will, we will rock you";
83
83
84
-
alert( str.match(/we/gi) ); // We,we (an array of 2 substrings that match)
84
+
alert( str.match(/we/gi) ); // We,we (অ্যারে আকারে এই ২টি সাবস্ট্রিং রিটার্ন করবে)
85
85
```
86
-
Please note that both `match:We`and`match:we`are found, because flag `pattern:i` makes the regular expression case-insensitive.
86
+
লক্ষ্য করুন এখানে `match:We`এবং`match:we`দুটিই দেখাবে, যেহেতু আমরা কেস-ইনসেনসিটিভ ফ্ল্যাগটি ব্যবহার করেছি।
87
87
88
-
2.If there's no such flag it returns only the first match in the form of an array, with the full match at index `0` and some additional details in properties:
88
+
2.যদি আমরা কোন ফ্ল্যাগ ব্যবহার না করি তাহলে এটি প্রথম মিলটিকে অ্যারে আকারে রিটার্ন করবে, সম্পূর্ন মিলটিকে আমরা ইনডেক্স `0`তে পাই এবং প্রপার্টিগুলোর অতিরিক্ত কিছু বর্ননাঃ
89
89
```js run
90
90
let str = "We will, we will rock you";
91
91
92
-
let result = str.match(/we/i); // without flag g
92
+
let result = str.match(/we/i); // ফ্ল্যাগ g ছাড়া
93
93
94
-
alert( result[0] ); // We (1st match)
94
+
alert( result[0] ); // We (১ম মিল)
95
95
alert( result.length ); // 1
96
96
97
97
// Details:
98
-
alert( result.index ); // 0 (position of the match)
98
+
alert( result.index ); // 0 (প্রাপ্ত মিলের পজিশন)
99
99
alert( result.input ); // We will, we will rock you (source string)
100
100
```
101
101
The array may have other indexes, besides `0`if a part of the regular expression is enclosed inparentheses. We'll cover that in the chapter <info:regexp-groups>.
102
102
103
-
3.And, finally, if there are no matches, `null`is returned (doesn't matter if there's flag `pattern:g`or not).
103
+
3. এবং, সর্বশেষে যদি কোন মিল খুঁজে পাওয়া না যায় `null` রিটার্ন করবে (এটি `pattern:g` ফ্ল্যাগের উপর নির্ভর করে না)।
104
104
105
-
This a very important nuance. If there are no matches, we don't receive an empty array, but instead receive `null`. Forgetting about that may lead to errors, e.g.:
105
+
একটি গুরুত্বপূর্ন ব্যাপার খেয়াল রাখা উচিত। যদি কোন মিল খুঁজে পাওয়া না গেলে এম্পটি স্ট্রিং এর বদলে `null` রিটার্ন করে। এজন্য এম্পটি চেকিংয়ের জন্য ভুলভাবে চেকিংয়ের জন্য এরর পেতে পারেন, যেমনঃ
106
106
107
107
```js run
108
108
let matches = "JavaScript".match(/HTML/); // = null
@@ -112,50 +112,48 @@ It has 3 working modes:
112
112
}
113
113
```
114
114
115
-
If we'd like the result to always be an array, we can write it this way:
115
+
নিম্নোক্ত উপায়ে রেজাল্ট আমরা সর্বদা অ্যারে হিসেবে চেক করতে পারিঃ
116
116
117
117
```js run
118
118
let matches = "JavaScript".match(/HTML/)*!* || []*/!*;
119
119
120
120
if (!matches.length) {
121
-
alert("No matches"); // now it works
121
+
alert("No matches"); // এখন এটি কাজ করবে
122
122
}
123
123
```
124
124
125
-
## Replacing:str.replace
125
+
## রিপ্লেসিংঃ str.replace
126
126
127
-
The method `str.replace(regexp, replacement)`replaces matches found using `regexp`in string `str`with`replacement`(all matches if there's flag `pattern:g`, otherwise, only the first one).
127
+
`str.replace(regexp, replacement)` মেথডটি `regexp` দ্বারা প্রাপ্ত সব মিলকে `replacement` করে `pattern:g` ফ্ল্যাগের জন্য, অন্যথায় শুধু প্রথম মিলটিকে রিপ্লেস করে।
128
128
129
-
For instance:
129
+
উদাহরণস্বরূপঃ
130
130
131
131
```js run
132
-
// no flag g
132
+
// g ফ্ল্যাগ ছাড়া
133
133
alert( "We will, we will".replace(/we/i, "I") ); // I will, we will
134
134
135
-
// with flag g
135
+
// g ফ্ল্যাগ সহ
136
136
alert( "We will, we will".replace(/we/ig, "I") ); // I will, I will
137
137
```
138
-
139
-
The second argument is the `replacement` string. We can use special character combinations in it to insert fragments of the match:
140
-
141
-
| Symbols | Action in the replacement string |
138
+
দ্বিতীয় আর্গুমেন্টে `replacement` স্ট্রিংটি পাস করা হয়। মিল খুঁজে পাওয়া অংশগুলো `replacement` এর সাথে ব্যবহার করতে আমরা কিছু স্পেশাল ক্যারেক্টার সংযুক্ত করতে পারি।
|<code>$`</code>|inserts a part of the string before the match|
145
143
|`$'`|inserts a part of the string after the match|
146
144
|`$n`|if `n` is a 1-2 digit number, then it inserts the contents of n-th parentheses, more about it in the chapter <info:regexp-groups>|
147
145
|`$<name>`|inserts the contents of the parentheses with the given `name`, more about it in the chapter <info:regexp-groups>|
148
146
|`$$`|inserts character `$` |
149
147
150
-
An example with `pattern:$&`:
148
+
`pattern:$&` এর একটি উদাহরণঃ
151
149
152
150
```js run
153
151
alert( "I love HTML".replace(/HTML/, "$& and JavaScript") ); // I love HTML and JavaScript
154
152
```
155
153
156
-
## Testing: regexp.test
154
+
## টেস্টিংঃ regexp.test
157
155
158
-
The method `regexp.test(str)`looks for at least one match, if found, returns `true`, otherwise`false`.
156
+
`regexp.test(str)`মেথডটি অন্তত একটি মিল খুঁজে পেলে `true` রিটার্ন করে, অন্যথায়`false` রিটার্ন করে।
159
157
160
158
```js run
161
159
let str ="I love JavaScript";
@@ -164,14 +162,15 @@ let regexp = /LOVE/i;
164
162
alert( regexp.test(str) ); // true
165
163
```
166
164
167
-
Later in this chapter we'll study more regular expressions, walk through more examples, and also meet other methods.
165
+
পরবর্তী অধ্যায়গুলোতে রেগুলার এক্সপ্রেশন সম্পর্কে আমরা আরো অনেক কিছু শিখব, আরো অনেক উদাহরণ এবং রেগুলার এক্সপ্রেশনের অন্যান্য মেথডগুলোও জানব।
166
+
167
+
মেথডগুলো সম্পর্কে বিস্তারিত আমরা এই অধ্যায়ে জানব <info:regexp-methods>.
168
168
169
-
Full information about the methods is given in the article <info:regexp-methods>.
170
169
171
-
## Summary
170
+
## সারাংশ
172
171
173
-
- A regular expression consists of a pattern and optional flags: `pattern:g`, `pattern:i`, `pattern:m`, `pattern:u`, `pattern:s`, `pattern:y`.
172
+
-রেগুলার এক্সপ্রেশন গঠিত হয় প্যাটার্ন এবং অপশনাল ফ্ল্যাগের সমন্বয়েঃ `pattern:g`, `pattern:i`, `pattern:m`, `pattern:u`, `pattern:s`, `pattern:y`।
174
173
- Without flags and special symbols (that we'll study later), the search by a regexp is the same as a substring search.
175
-
- The method `str.match(regexp)`looks for matches: all of them if there's `pattern:g` flag, otherwise, only the first one.
176
-
- The method `str.replace(regexp, replacement)`replaces matches found using `regexp`with `replacement`: all of them if there's `pattern:g`flag, otherwise only the first one.
177
-
- The method `regexp.test(str)`returns `true` if there's at least one match, otherwise, it returns `false`.
174
+
-`str.match(regexp)`মেথডটি `pattern:g` ফ্ল্যাগের জন্য প্যাটার্নের সাথে সকল মিল খুঁজে, অন্যথায় শুধু প্রথম মিলটি খুঁজে।
175
+
-`str.replace(regexp, replacement)`মেথডটি `regexp`দ্বারা প্রাপ্ত সব মিলকে `replacement` করে `pattern:g`ফ্ল্যাগের জন্য, অন্যথায় শুধু প্রথম মিলটিকে রিপ্লেস করে।
176
+
-`regexp.test(str)`মেথডটি অন্তত একটি মিল খুঁজে পেলে `true` রিটার্ন করে, অন্যথায় `false` রিটার্ন করে।
0 commit comments