Skip to content

Commit 1604958

Browse files
committed
resolve conflict
1 parent 357a8d1 commit 1604958

File tree

1 file changed

+2
-56
lines changed
  • 9-regular-expressions/01-regexp-introduction

1 file changed

+2
-56
lines changed

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

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,22 @@
11
# Pattern dan flag
22

3-
<<<<<<< HEAD
43
Expresi reguler merupakan cara yang kuat untuk mencari dan mengganti dalam teks.
54

65
Di JavaScript, mereka tersedia sebagai objek [RegExp](mdn:js/RegExp), dan bisa diintegrasi dalam metode string.
7-
=======
8-
Regular expressions are patterns that provide a powerful way to search and replace in text.
9-
10-
In JavaScript, they are available via the [RegExp](mdn:js/RegExp) object, as well as being integrated in methods of strings.
11-
>>>>>>> 2b5ac971c1bd8abe7b17cdcf724afd84799b6cbd
126

137
## Expresi Reguler
148

159
Expresi reguler ("regexp", atau hanya "reg") terdiri dari *pola* dan *flag* opsional.
1610

17-
<<<<<<< HEAD
1811
Ada dua sintaks untuk membuat objek ekspresi reguler.
19-
=======
20-
There are two syntaxes that can be used to create a regular expression object.
21-
>>>>>>> 2b5ac971c1bd8abe7b17cdcf724afd84799b6cbd
2212

2313
Syntax panjang:
2414

2515
```js
2616
regexp = new RegExp("pattern", "flag");
2717
```
2818

29-
<<<<<<< HEAD
30-
...Dan yang pendek, menggunakan garis miring `"/"`:
31-
=======
32-
And the "short" one, using slashes `"/"`:
33-
>>>>>>> 2b5ac971c1bd8abe7b17cdcf724afd84799b6cbd
19+
Dan yang "pendek", menggunakan garis miring `"/"`:
3420

3521
```js
3622
regexp = /pattern/; // tanpa flag
@@ -39,19 +25,11 @@ regexp = /pattern/gmi; // dengan flag g,m dan i (untuk segera ditutup)
3925

4026
Garis miring `pattern:/.../` memberitahu JavaScript bahwa kita sedang membuat regular expression. Mereka memiliki peran yang sama dengan tanda petik untuk *string*.
4127

42-
<<<<<<< HEAD
4328
Untuk kedua kasus `regexp` menjadi object kelas `RegExp` built-in.
4429

4530
Perbedaan utama antara kedua syntax ini iadalah garis miring `pattern:/.../` melarang penyisipan expresi (seperti string dengan `${...}`). Mereka benar-benar static.
4631

4732
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:
48-
=======
49-
In both cases `regexp` becomes an instance of the built-in `RegExp` class.
50-
51-
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.
52-
53-
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:
54-
>>>>>>> 2b5ac971c1bd8abe7b17cdcf724afd84799b6cbd
5533

5634
```js
5735
let tag = prompt("What tag do you want to find?", "h2");
@@ -69,11 +47,7 @@ Cuma ada 6 di antaranya di JavaScript:
6947
: With this flag the search is case-insensitive: no difference between `A` and `a` (see the example below).
7048

7149
`pattern:g`
72-
<<<<<<< HEAD
73-
: Dengan flag ini pencarian mencari semua kecocokan, tanpanya -- hanya yang pertama.
74-
=======
75-
: With this flag the search looks for all matches, without it -- only the first match is returned.
76-
>>>>>>> 2b5ac971c1bd8abe7b17cdcf724afd84799b6cbd
50+
: Dengan flag ini pencarian mencari semua kecocokan, tanpanya -- hanya yang pertama yang dikembalikan.
7751

7852
`pattern:m`
7953
: Mode baris-ganda (dibahas di bab <info:regexp-multiline-mode>).
@@ -97,11 +71,7 @@ Skema warnanya adalah:
9771

9872
## Searching: str.match
9973

100-
<<<<<<< HEAD
10174
Seperti yang dikatakan sebelumnya, regular expressions terintegrasi dengan metode string.
102-
=======
103-
As mentioned previously, regular expressions are integrated with string methods.
104-
>>>>>>> 2b5ac971c1bd8abe7b17cdcf724afd84799b6cbd
10575

10676
Metode ini `str.match(regexp)` mencari semua kecocokan `regexp` di dalam string `str`.
10777

@@ -132,11 +102,7 @@ Ia punya 3 mode kerja:
132102

133103
3. Dan, akhirnya, jika tak ada kecocokan, `null` dikembalikan (tak peduli apakah ada flag `pattern:g` atau tidak).
134104

135-
<<<<<<< HEAD
136105
Itu nuansa paling penting. Jika tak ada kecocokan, kita tak mendapatkan array kosong, tapi `null`. Melupakan itu bisa membawa galat, misal:
137-
=======
138-
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.:
139-
>>>>>>> 2b5ac971c1bd8abe7b17cdcf724afd84799b6cbd
140106

141107
```js run
142108
let matches = "JavaScript".match(/HTML/); // = null
@@ -146,11 +112,7 @@ Ia punya 3 mode kerja:
146112
}
147113
```
148114

149-
<<<<<<< HEAD
150115
Jika kita mau hasilnya selalu array, kita bisa menulisnya seperti ini:
151-
=======
152-
If we'd like the result to always be an array, we can write it this way:
153-
>>>>>>> 2b5ac971c1bd8abe7b17cdcf724afd84799b6cbd
154116

155117
```js run
156118
let matches = "JavaScript".match(/HTML/)*!* || []*/!*;
@@ -162,11 +124,7 @@ Ia punya 3 mode kerja:
162124

163125
## Mengganti: str.replace
164126

165-
<<<<<<< HEAD
166127
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).
167-
=======
168-
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).
169-
>>>>>>> 2b5ac971c1bd8abe7b17cdcf724afd84799b6cbd
170128

171129
Misalnya:
172130

@@ -206,26 +164,14 @@ let regexp = /LOVE/i;
206164
alert( regexp.test(str) ); // true
207165
```
208166

209-
<<<<<<< HEAD
210167
Lebih lanjut di bab ini kita akan mempelajari lebih regular expression, menjumpai banyak contoh dan menemui metode lainnya.
211-
=======
212-
Later in this chapter we'll study more regular expressions, walk through more examples, and also meet other methods.
213-
>>>>>>> 2b5ac971c1bd8abe7b17cdcf724afd84799b6cbd
214168

215169
Informasi penuh tentang metode ini diberikan dalam artikel <info:regexp-methods>.
216170

217171
## Ringkasan
218172

219-
<<<<<<< HEAD
220173
- Regular expression terdiri atas pola dan flag opsional: `pattern:g`, `pattern:i`, `pattern:m`, `pattern:u`, `pattern:s`, `pattern:y`.
221174
- Tanpa flag dan simbol spesial yang akan kita pelajari nanti, pencarian menggunakan regexp sama dengan pencarian substring.
222175
- Metode `str.match(regexp)` mencari kecocokan: semuanya jika ada flag `pattern:g`, kalau tidak cuma yang pertama.
223176
- Metode `str.replace(regexp, replacement)` mengganti kecocokan dengan `regexp` by `replacement`: semuanya jika ada flag `pattern:g`, selain itu cuma yang pertama.
224177
- Metode `regexp.test(str)` mengembalikan `true` jika ada paling tidak satu kecocokan, kalau tidak `false`.
225-
=======
226-
- A regular expression consists of a pattern and optional flags: `pattern:g`, `pattern:i`, `pattern:m`, `pattern:u`, `pattern:s`, `pattern:y`.
227-
- Without flags and special symbols (that we'll study later), the search by a regexp is the same as a substring search.
228-
- The method `str.match(regexp)` looks for matches: all of them if there's `pattern:g` flag, otherwise, only the first one.
229-
- 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.
230-
- The method `regexp.test(str)` returns `true` if there's at least one match, otherwise, it returns `false`.
231-
>>>>>>> 2b5ac971c1bd8abe7b17cdcf724afd84799b6cbd

0 commit comments

Comments
 (0)