Skip to content

Commit 228f94d

Browse files
committed
resolving conflict
1 parent ff88446 commit 228f94d

File tree

1 file changed

+48
-143
lines changed
  • 9-regular-expressions/01-regexp-introduction

1 file changed

+48
-143
lines changed

9-regular-expressions/01-regexp-introduction/article.md

Lines changed: 48 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22

33
Expresi reguler merupakan cara yang kuat untuk mencari dan mengganti dalam teks.
44

5-
<<<<<<< HEAD
6-
Di JavaScript, mereka tersedia sebagai objek `RegExp`, dan bisa diintegrasi dalam metode string.
7-
=======
8-
In JavaScript, they are available as [RegExp](mdn:js/RegExp) object, and also integrated in methods of strings.
9-
>>>>>>> a0bfa924a17cad8e7fee213904b27dbf57c2dbac
5+
Di JavaScript, mereka tersedia sebagai objek [RegExp](mdn:js/RegExp), dan bisa diintegrasi dalam metode string.
106

117
## Expresi Reguler
128

@@ -27,71 +23,43 @@ regexp = /pattern/; // tanpa flag
2723
regexp = /pattern/gmi; // dengan flag g,m dan i (untuk segera ditutup)
2824
```
2925

30-
<<<<<<< HEAD
31-
Garing miring `"/"` akan memberitahu JavaScript bahwa kita sedang membuat ekspresi reguler. Mereka memiliki peran yang sama seperti *quotes* untuk *strings*.
26+
Garis miring `pattern:/.../` memberitahu JavaScript bahwa kita sedang membuat regular expression. Mereka memiliki peran yang sama dengan tanda petik untuk *string*.
3227

33-
## Penggunaan
28+
Untuk kedua kasus `regexp` menjadi object kelas `RegExp` built-in.
3429

35-
Untuk mencari di dalam sebuah string, kita dapat menggunakan metode [*search*](mdn:js/String/search).
30+
Perbedaan utama antara kedua syntax ini iadalah garis miring `pattern:/.../` melarang penyisipan expresi (seperti string dengan `${...}`). Mereka benar-benar static.
3631

37-
Berikut contohnya:
38-
39-
```js run
40-
let str = "I love JavaScript!"; // akan mencari disini
41-
=======
42-
Slashes `pattern:/.../` tell JavaScript that we are creating a regular expression. They play the same role as quotes for strings.
43-
44-
In both cases `regexp` becomes an object of the built-in `RegExp` class.
45-
46-
The main difference between these two syntaxes is that slashes `pattern:/.../` do not allow to insert expressions (like strings with `${...}`). They are fully static.
47-
48-
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 used when we need to create a regexp "on the fly", from a dynamically generated string, for instance:
32+
Garis miring digunakan saat kita tahu regular expression saat menulis kode -- dan itu situasi paling umum. Ketika `RegExp baru` digunakan saat kita harus membuat regexp baru "on the fly", dari string yang digenerate secara dinamis, misalnya:
4933

5034
```js
5135
let tag = prompt("What tag do you want to find?", "h2");
52-
>>>>>>> a0bfa924a17cad8e7fee213904b27dbf57c2dbac
5336

54-
let regexp = new RegExp(`<${tag}>`); // same as /<h2>/ if answered "h2" in the prompt above
37+
let regexp = new RegExp(`<${tag}>`); // sama dengan /<h2>/ jika dijawab "h2" di prompt di atas
5538
```
5639

57-
<<<<<<< HEAD
58-
Methode `str.search` akan mencari pola `pattern:/love/` dan mengembalikan posisi `pattern:/love/` di string tersebut. Seperti yang kita duga, `pattern:/love/` adalah pola yang paling sederhana. Yang dilakukannya hanyalah mencari *substring* biasa.
59-
60-
Code di atas sama seperti berikut:
61-
62-
```js run
63-
let str = "I love JavaScript!"; // akan mencari disini
64-
=======
65-
## Flags
40+
## Flag
6641

67-
Regular expressions may have flags that affect the search.
42+
Regular expression bisa punya flag yang mempengaruhi pencarian.
6843

69-
There are only 6 of them in JavaScript:
70-
>>>>>>> a0bfa924a17cad8e7fee213904b27dbf57c2dbac
44+
Cuma ada 6 di antaranya di JavaScript:
7145

7246
`pattern:i`
7347
: With this flag the search is case-insensitive: no difference between `A` and `a` (see the example below).
7448

75-
<<<<<<< HEAD
76-
Jadi, mencari `pattern:/love/` sama seperti mencari `"love"`.
77-
78-
Tapi itu hanya untuk saat ini. Kita akan membuat ekspresi reguler yang lebih kompleks dengan kekuatan *search* yang jauh lebih banyak.
79-
=======
8049
`pattern:g`
81-
: With this flag the search looks for all matches, without it -- only the first one.
50+
: Dengan flag ini pencarian mencari semua kecocokan, tanpanya -- hanya yang pertama.
8251

8352
`pattern:m`
84-
: Multiline mode (covered in the chapter <info:regexp-multiline-mode>).
53+
: Mode baris-ganda (dibahas di bab <info:regexp-multiline-mode>).
8554

8655
`pattern:s`
87-
: Enables "dotall" mode, that allows a dot `pattern:.` to match newline character `\n` (covered in the chapter <info:regexp-character-classes>).
56+
: Menyalakan mode "dotall", yang membolehkan dot `pattern:.` untuk cocok dengan karakter baris-baru `\n` (dibahas di bab <info:regexp-character-classes>).
8857

8958
`pattern:u`
90-
: Enables full unicode support. The flag enables correct processing of surrogate pairs. More about that in the chapter <info:regexp-unicode>.
59+
: Menyalakan dukungan penuh unicode. Flag ini menyalakan pemrosesan yang benar dari pasangan pengganti. Lebih lanjut tentang itu di bab <info:regexp-unicode>.
9160

9261
`pattern:y`
93-
: "Sticky" mode: searching at the exact position in the text (covered in the chapter <info:regexp-sticky>)
94-
>>>>>>> a0bfa924a17cad8e7fee213904b27dbf57c2dbac
62+
: Mode "sticky": mencari posisi tepat di dalam teks (dibahas di bab <info:regexp-sticky>)
9563

9664
```smart header="Warna"
9765
Skema warnanya adalah:
@@ -103,85 +71,38 @@ Skema warnanya adalah:
10371

10472
## Searching: str.match
10573

106-
<<<<<<< HEAD
107-
````smart header="Kapan harus menggunakan `new RegExp`?"
108-
Biasanya kita menggunakan sintaks pendek `/.../`. Tetapi itu tidak mendukung penyisipan variabel menggunakan sintaks `${...}`.
109-
110-
Di sisi lain, `new RegExp` memungkinkan untuk membangun pola secara dinamis dari string, jadi lebih fleksibel.
111-
112-
Berikut contoh dari *regexp* yang dihasilkan secara dinamis:
113-
114-
```js run
115-
let tag = prompt("Tag mana yang ingin Kamu cari?", "h2");
116-
let regexp = new RegExp(`<${tag}>`);
117-
118-
// mencari <h2> secara default
119-
alert( "<h1> <h2> <h3>".search(regexp));
120-
```
121-
````
122-
=======
123-
As it was said previously, regular expressions are integrated with string methods.
74+
Seperti yang dikatakan sebelumnya, regular expressions terintegrasi dengan metode string.
12475

125-
The method `str.match(regexp)` finds all matches of `regexp` in the string `str`.
76+
Metode ini `str.match(regexp)` mencari semua kecocokan `regexp` di dalam string `str`.
12677

127-
It has 3 working modes:
78+
Ia punya 3 mode kerja:
12879

129-
1. If the regular expression has flag `pattern:g`, it returns an array of all matches:
80+
1. Jika regular expression punya flag `pattern:g`, ia mengembalikan array semua kecocokan:
13081
```js run
13182
let str = "We will, we will rock you";
13283

133-
alert( str.match(/we/gi) ); // We,we (an array of 2 substrings that match)
84+
alert( str.match(/we/gi) ); // We,we (array 2 substring yang cocok)
13485
```
135-
Please note that both `match:We` and `match:we` are found, because flag `pattern:i` makes the regular expression case-insensitive.
136-
>>>>>>> a0bfa924a17cad8e7fee213904b27dbf57c2dbac
86+
Tolong ingat bahwa kedua `match:We` dan `match:we` ditemukan, karena flag `pattern:i` membuat regular expression case-insensitive.
13787

13888
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:
13989
```js run
14090
let str = "We will, we will rock you";
14191
142-
<<<<<<< HEAD
143-
## Flag
144-
145-
Expresi reguler mungkin memiliki *flag* yang dapat mempengaruhi *search*.
146-
147-
Mereka hanya ada 6 di Javascript:
148-
149-
`i`
150-
: Dengan *flag* ini, *search* tidak peka terhadap huruf besar maupun kecil: tidak ada perbedaan antara `A` and `a` (lihat contohnya di bawah ini).
151-
152-
`g`
153-
: Dengan *flag* ini, *search* akan mencari semua yang cocok dengannya, tanpa itu -- hanya yang pertama yang cocok (kita akan melihat kegunaan *flag* `g` di bab berikutnya).
154-
155-
`m`
156-
: Mode *Multiline* (tercantum di dalam bab <info:regexp-multiline-mode>).
157-
158-
`s`
159-
: Mode *Dotall*, memungkinkan `.` untuk cocok dengan baris baru (tecantum di dalam bab <info:regexp-character-classes>).
160-
161-
`u`
162-
: Mengaktifkan dukungan unicode secara penuh. *Flag* ini memungkinkan untuk memproses pasangan pengganti (unicode) yang benar. Lebih lanjut tentangnya ada di dalam bab <info:regexp-unicode>.
163-
164-
`y`
165-
: Mode *Sticky* (tercantum di dalam bab <info:regexp-sticky>)
166-
167-
Kita akan membahas semua *flag* tersebut lebih lanjut di dalam tutorial.
168-
169-
Untuk sekarang, *flag* paling sederhana adalah `i`, berikut contohnya:
170-
=======
171-
let result = str.match(/we/i); // without flag g
92+
let result = str.match(/we/i); // tanpa flag g
17293
17394
alert( result[0] ); // We (1st match)
17495
alert( result.length ); // 1
17596
176-
// Details:
177-
alert( result.index ); // 0 (position of the match)
97+
// Detil:
98+
alert( result.index ); // 0 (posisi kecocokan)
17899
alert( result.input ); // We will, we will rock you (source string)
179100
```
180101
The array may have other indexes, besides `0` if a part of the regular expression is enclosed in parentheses. We'll cover that in the chapter <info:regexp-groups>.
181102

182-
3. And, finally, if there are no matches, `null` is returned (doesn't matter if there's flag `pattern:g` or not).
103+
3. Dan, akhirnya, jika tak ada kecocokan, `null` dikembalikan (tak peduli apakah ada flag `pattern:g` atau tidak).
183104

184-
That's a very important nuance. If there are no matches, we get not an empty array, but `null`. Forgetting about that may lead to errors, e.g.:
105+
Itu nuansa paling penting. Jika tak ada kecocokan, kita tak mendapatkan array kosong, tapi `null`. Melupakan itu bisa membawa galat, misal:
185106

186107
```js run
187108
let matches = "JavaScript".match(/HTML/); // = null
@@ -191,59 +112,50 @@ Untuk sekarang, *flag* paling sederhana adalah `i`, berikut contohnya:
191112
}
192113
```
193114

194-
If we'd like the result to be always an array, we can write it this way:
115+
Jika kita mau hasilnya selalu array, kita bisa menulisnya seperti ini:
195116

196117
```js run
197118
let matches = "JavaScript".match(/HTML/)*!* || []*/!*;
198119
199120
if (!matches.length) {
200-
alert("No matches"); // now it works
121+
alert("No matches"); // sekarang ini bekerja
201122
}
202123
```
203124

204-
## Replacing: str.replace
125+
## Mengganti: str.replace
205126

206-
The method `str.replace(regexp, replacement)` replaces matches with `regexp` in string `str` with `replacement` (all matches, if there's flag `pattern:g`, otherwise only the first one).
127+
Metode `str.replace(regexp, replacement)` mengganti kecocokan dengan `regexp` dalam string `str` dengan `replacement` (semua kecocokan, jika ada flag `pattern:g`, kalau tidak cuma yang pertama).
207128

208-
For instance:
209-
>>>>>>> a0bfa924a17cad8e7fee213904b27dbf57c2dbac
129+
Misalnya:
210130

211131
```js run
212-
// no flag g
132+
// tak ada flag g
213133
alert( "We will, we will".replace(/we/i, "I") ); // I will, we will
214134
215-
// with flag g
135+
// dengan flag g
216136
alert( "We will, we will".replace(/we/ig, "I") ); // I will, I will
217137
```
218138

219-
The second argument is the `replacement` string. We can use special character combinations in it to insert fragments of the match:
220-
221-
<<<<<<< HEAD
222-
alert( str.search(/LOVE/i) ); // 2 (lowercased ditemukan)
223-
224-
alert( str.search(/LOVE/) ); // -1 (tidak ada yang ditemukan tanpa flag 'i')
225-
```
139+
Argumen kedua adalah string `replacement`. Kita bisa memakai kombinasi karakter spesial di dalamnya untuk menyisipkan fragment kecocokan:
226140

227-
*Flag* `i` telah membuat ekpresi reguler menjadi lebih kuat daripada *search substring* biasanya. Tapi masih ada banyak lagi. Kita akan membahas *flag* lain dan fitur *regxp* di dalam bab berikutnya.
228-
=======
229-
| Symbols | Action in the replacement string |
141+
| Simbol | Aksi di string pengganti |
230142
|--------|--------|
231-
|`$&`|inserts the whole match|
232-
|<code>$&#096;</code>|inserts a part of the string before the match|
233-
|`$'`|inserts a part of the string after the match|
143+
|`$&`|menyisipkan seluruh kecocokan|
144+
|<code>$&#096;</code>|menyisipkan bagian string sebelum kecocokan|
145+
|`$'`|menyisipkan bagian string setelah kecocokan|
234146
|`$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>|
235-
|`$<name>`|inserts the contents of the parentheses with the given `name`, more about it in the chapter <info:regexp-groups>|
236-
|`$$`|inserts character `$` |
147+
|`$<name>`|menyisipkan konten tanda kurung dengan `name` yang diberikan, lebih lanjut tentang ini ada di bab <info:regexp-groups>|
148+
|`$$`|menyisipkan karakter `$` |
237149

238-
An example with `pattern:$&`:
150+
Contohnya dengan `pattern:$&`:
239151

240152
```js run
241153
alert( "I love HTML".replace(/HTML/, "$& and JavaScript") ); // I love HTML and JavaScript
242154
```
243155

244156
## Testing: regexp.test
245157

246-
The method `regexp.test(str)` looks for at least one match, if found, returns `true`, otherwise `false`.
158+
Metode `regexp.test(str)` mencari paling tidak 1 kecocokan, jika ditemukan, mengembalikan `true`, kalau tidak `false`.
247159

248160
```js run
249161
let str = "I love JavaScript";
@@ -252,21 +164,14 @@ let regexp = /LOVE/i;
252164
alert( regexp.test(str) ); // true
253165
```
254166

255-
Further in this chapter we'll study more regular expressions, come across many other examples and also meet other methods.
256-
>>>>>>> a0bfa924a17cad8e7fee213904b27dbf57c2dbac
167+
Lebih lanjut di bab ini kita akan mempelajari lebih regular expression, menjumpai banyak contoh dan menemui metode lainnya.
257168

258-
Full information about the methods is given in the article <info:regexp-methods>.
169+
Informasi penuh tentang metode ini diberikan dalam artikel <info:regexp-methods>.
259170

260171
## Ringkasan
261172

262-
<<<<<<< HEAD
263-
- Ekspresi reguler terdiri dari *pattern* dan opsional *flag*: `g`, `i`, `m`, `u`, `s`, `y`.
264-
- Tanpa *flag* dan simbol khusus yang akan kita pelajari nanti, *search* dengan *regexp* sama seperti *search* dengan substring.
265-
- Metode `str.search(regexp)` mengembalikan *index* yang cocok atau `-1` jika tidak ada yang cocok. Dalam bab selanjutnya kita akan melihat metode lain.
266-
=======
267-
- A regular expression consists of a pattern and optional flags: `pattern:g`, `pattern:i`, `pattern:m`, `pattern:u`, `pattern:s`, `pattern:y`.
268-
- Without flags and special symbols that we'll study later, the search by a regexp is the same as a substring search.
269-
- The method `str.match(regexp)` looks for matches: all of them if there's `pattern:g` flag, otherwise only the first one.
270-
- The method `str.replace(regexp, replacement)` replaces matches with `regexp` by `replacement`: all of them if there's `pattern:g` flag, otherwise only the first one.
271-
- The method `regexp.test(str)` returns `true` if there's at least one match, otherwise `false`.
272-
>>>>>>> a0bfa924a17cad8e7fee213904b27dbf57c2dbac
173+
- Regular expression terdiri atas pola dan flag opsional: `pattern:g`, `pattern:i`, `pattern:m`, `pattern:u`, `pattern:s`, `pattern:y`.
174+
- Tanpa flag dan simbol spesial yang akan kita pelajari nanti, pencarian menggunakan regexp sama dengan pencarian substring.
175+
- Metode `str.match(regexp)` mencari kecocokan: semuanya jika ada flag `pattern:g`, kalau tidak cuma yang pertama.
176+
- Metode `str.replace(regexp, replacement)` mengganti kecocokan dengan `regexp` by `replacement`: semuanya jika ada flag `pattern:g`, selain itu cuma yang pertama.
177+
- Metode `regexp.test(str)` mengembalikan `true` jika ada paling tidak satu kecocokan, kalau tidak `false`.

0 commit comments

Comments
 (0)