Skip to content

Commit 6e83002

Browse files
authored
Merge pull request #203 from msisaifu/lookaround
Lookahead and lookbehind
2 parents ec5c967 + 34fd845 commit 6e83002

File tree

5 files changed

+85
-84
lines changed

5 files changed

+85
-84
lines changed

Diff for: 9-regular-expressions/14-regexp-lookahead-lookbehind/1-find-non-negative-integers/solution.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

2-
The regexp for an integer number is `pattern:\d+`.
2+
পূর্ণসংখ্যার রেগুলার এক্সপ্রেশন হল `pattern:\d+`
33

4-
We can exclude negatives by prepending it with the negative lookahead: `pattern:(?<!-)\d+`.
4+
আমরা ঋণাত্নক সংখ্যাগুলোকে বাদ দিতে পারি নেগেটিভ লুকবিহাইন্ড এর মাধ্যমে: `pattern:(?<!-)\d+`
55

6-
Although, if we try it now, we may notice one more "extra" result:
6+
সম্ভবত, আমরা এটি চেষ্টা করতে পারি, তবে এক্ষেত্রে আমরা "অতিরিক্ত" ফলাফল পাব:
77

88
```js run
99
let regexp = /(?<!-)\d+/g;
@@ -13,11 +13,11 @@ let str = "0 12 -5 123 -18";
1313
console.log( str.match(regexp) ); // 0, 12, 123, *!*8*/!*
1414
```
1515

16-
As you can see, it matches `match:8`, from `subject:-18`. To exclude it, we need to ensure that the regexp starts matching a number not from the middle of another (non-matching) number.
16+
এখানে দেখতে পাচ্ছি, `subject:-18` এর মিল `match:8`। এটিকে বাদ দিতে হলে, আমাদের নিশ্চিত হতে হবে রেগুলার এক্সপ্রেশনটি অন্য সংখ্যার মাঝে যাচাই করবে না।
1717

18-
We can do it by specifying another negative lookbehind: `pattern:(?<!-)(?<!\d)\d+`. Now `pattern:(?<!\d)` ensures that a match does not start after another digit, just what we need.
18+
এজন্য আমরা আরো একটি লুকবিহাইন্ড ব্যবহার করতে পারি: `pattern:(?<!-)(?<!\d)\d+`। এখন `pattern:(?<!\d)` এর দ্বারা নিশ্চিত করছি কোন ম্যাচ অন্য ডিজিটের মাঝ থেকে যাচাই করবে না।
1919

20-
We can also join them into a single lookbehind here:
20+
আমরা একে একটি লুকবিহাইন্ডে সংযোগ করতে পারি:
2121

2222
```js run
2323
let regexp = /(?<![-\d])\d+/g;

Diff for: 9-regular-expressions/14-regexp-lookahead-lookbehind/1-find-non-negative-integers/task.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Find non-negative integers
1+
# অঋণাত্নক পূর্ণসংখ্যার অনুসন্ধান
22

3-
There's a string of integer numbers.
3+
এখানে পূর্ণসংখ্যার একটি স্ট্রিং আছে।
44

5-
Create a regexp that looks for only non-negative ones (zero is allowed).
5+
একটি রেগুলার এক্সপ্রেশন লিখুন যা অঋণাত্নক পূর্ণসংখ্যার অনুসন্ধান করে (শূন্যও অনুসন্ধান করবে)।
66

7-
An example of use:
7+
উদাহরণ:
88
```js
9-
let regexp = /your regexp/g;
9+
let regexp = /আপনার প্যাটার্ন/g;
1010

1111
let str = "0 12 -5 123 -18";
1212

Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
In order to insert after the `<body>` tag, we must first find it. We can use the regular expression pattern `pattern:<body.*>` for that.
1+
`<body>` ট্যাগ ভিতরে নতুন ট্যাগ স্থাপনের জন্য, আমাদের প্রথমে এটি খুঁজে বের করতে হবে। এজন্য আমরা এই রেগুলার এক্সপ্রেশনটি ব্যবহার করব `pattern:<body.*>`
22

3-
In this task we don't need to modify the `<body>` tag. We only need to add the text after it.
3+
এই টাস্কের জন্য আমাদের `<body>` ট্যাগকে প্রতিস্থাপিত করা লাগবে না। আমাদের শুধুমাত্র ট্যাক্সটিকে সংযোগ করতে হবে।
44

5-
Here's how we can do it:
5+
এখানে দেখুন আমরা কিভাবে এটি করতে পারি:
66

77
```js run
88
let str = '...<body style="...">...';
@@ -11,9 +11,10 @@ str = str.replace(/<body.*>/, '$&<h1>Hello</h1>');
1111
alert(str); // ...<body style="..."><h1>Hello</h1>...
1212
```
1313

14-
In the replacement string `$&` means the match itself, that is, the part of the source text that corresponds to `pattern:<body.*>`. It gets replaced by itself plus `<h1>Hello</h1>`.
1514

16-
An alternative is to use lookbehind:
15+
রিপ্লেসমেন্ট স্ট্রিংয়ে `$&` দ্বারা বুঝায় মিলের কন্টেন্টটি অর্থাৎ সোর্সের ট্যাক্সটি `pattern:<body.*>`। মিলকৃত কন্টেন্টটি অতঃপর `<h1>Hello</h1>`
16+
17+
বিকল্প আরেকটি হতে পারে লুকবিহাইন্ড:
1718

1819
```js run
1920
let str = '...<body style="...">...';
@@ -22,15 +23,15 @@ str = str.replace(/(?<=<body.*>)/, `<h1>Hello</h1>`);
2223
alert(str); // ...<body style="..."><h1>Hello</h1>...
2324
```
2425

25-
As you can see, there's only lookbehind part in this regexp.
26+
এখানে দেখতে পাচ্ছি, এখানে রেগুলার এক্সপ্রেশনে শুধুমাত্র লুকবিহাইন্ডের অংশটি আছে।
2627

27-
It works like this:
28-
- At every position in the text.
29-
- Check if it's preceeded by `pattern:<body.*>`.
30-
- If it's so then we have the match.
28+
এটি এভাবে কাজ করছে:
29+
- টেক্সটের প্রতিটি পজিশনে।
30+
- যাচাই করছে পূর্বে `pattern:<body.*>` আছে কিনা।
31+
- যদি থাকে তাহলে আমাদের মিলটি পাব।
3132

32-
The tag `pattern:<body.*>` won't be returned. The result of this regexp is literally an empty string, but it matches only at positions preceeded by `pattern:<body.*>`.
33+
`pattern:<body.*>` ট্যাগটি রিটার্ন করবে না। সুতরাং রেজাল্ট হবে এম্পটি স্ট্রিং, কিন্ত ম্যাচটির অবস্থান হবে `pattern:<body.*>` এর পরের অবস্থানটি।
3334

34-
So we replaces the "empty line", preceeded by `pattern:<body.*>`, with `<h1>Hello</h1>`. That's the insertion after `<body>`.
35+
সুতরা আমরা "empty line" টিকে রিপ্লেস করব `<h1>Hello</h1>` দ্বারা যার পূর্বে `pattern:<body.*>` আছে। সুতরাং নতুন ট্যাগটি হবে `<body>` এর পর।
3536

36-
P.S. Regexp flags, such as `pattern:s` and `pattern:i` can also useful: `pattern:/<body.*>/si`. The `pattern:s` flag makes the dot `pattern:.` match a newline character, and `pattern:i` flag makes `pattern:<body>` also match `match:<BODY>` case-insensitively.
37+
লক্ষ্যনীয় রেগুলার এক্সপ্রেশন ফ্ল্যাগ, যেমন `pattern:s` এবং `pattern:i` দরকারী: `pattern:/<body.*>/si``pattern:s` ফ্ল্যাগটি `pattern:.` দ্বারা নিউলাইন ক্যারাক্টারকেও বুঝায়, এবং `pattern:i` ফ্ল্যাগ কেস-ইন্সেসিটিভ বুঝায় `pattern:<body>` এটি `match:<BODY>` এর সাথেও ম্যাচ করবে।

Diff for: 9-regular-expressions/14-regexp-lookahead-lookbehind/2-insert-after-head/task.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
# Insert After Head
1+
# Body এর ভিতরে H1 ট্যাগ
22

3-
We have a string with an HTML Document.
3+
HTML Document এর একটি স্ট্রিং আছে।
44

5-
Write a regular expression that inserts `<h1>Hello</h1>` immediately after `<body>` tag. The tag may have attributes.
5+
একটি রেগুলার এক্সপ্রেশন লিখুন যার মাধ্যমে `<body>` ট্যাগ এর পর `<h1>Hello</h1>` কে সংযোগ করতে পারি। ট্যাগটির একাধিক অ্যাট্রিবিউট থাকতে পারে।
66

7-
For instance:
7+
উদাহরণস্বরূপ:
88

99
```js
10-
let regexp = /your regular expression/;
11-
10+
let regexp = /আপনার প্যাটার্ন/;
1211
let str = `
1312
<html>
1413
<body style="height: 200px">
@@ -20,7 +19,7 @@ let str = `
2019
str = str.replace(regexp, `<h1>Hello</h1>`);
2120
```
2221

23-
After that the value of `str` should be:
22+
এর পর `str` এর মান হবে:
2423
```html
2524
<html>
2625
<body style="height: 200px"><h1>Hello</h1>

0 commit comments

Comments
 (0)