Skip to content

Commit 34cf61c

Browse files
committed
Translate tasks in 5-regular-expressions/09-regexp-groups/
1 parent f6e91c1 commit 34cf61c

File tree

8 files changed

+48
-48
lines changed

8 files changed

+48
-48
lines changed

5-regular-expressions/09-regexp-groups/1-find-webcolor-3-or-6/solution.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
A regexp to search 3-digit color `#abc`: `pattern:/#[a-f0-9]{3}/i`.
1+
3桁の色 `#abc` を検索する正規表現は `pattern:/#[a-f0-9]{3}/i` です。
22

3-
We can add exactly 3 more optional hex digits. We don't need more or less. Either we have them or we don't.
3+
正確に3つの任意の16進数を指定できます。 私たちはそれ以上もそれ以下も必要ではありません。それを持っているか、持っていないかのどちらかです。
44

5-
The simplest way to add them -- is to append to the regexp: `pattern:/#[a-f0-9]{3}([a-f0-9]{3})?/i`
5+
それらを追加する最も単純な方法は -- 正規表現に追加することです: `pattern:/#[a-f0-9]{3}([a-f0-9]{3})?/i`
66

7-
We can do it in a smarter way though: `pattern:/#([a-f0-9]{3}){1,2}/i`.
7+
よりスマートな方法で書くこともできます: `pattern:/#([a-f0-9]{3}){1,2}/i`.
88

9-
Here the regexp `pattern:[a-f0-9]{3}` is in parentheses to apply the quantifier `pattern:{1,2}` to it as a whole.
9+
ここで正規表現 `pattern:[a-f0-9]{3}` は括弧の中にあり、全体として量指定子 `pattern:{1,2}` を適用します。
1010

11-
In action:
11+
動作:
1212

1313
```js run
1414
let reg = /#([a-f0-9]{3}){1,2}/gi;
@@ -18,7 +18,7 @@ let str = "color: #3f3; background-color: #AA00ef; and: #abcd";
1818
alert( str.match(reg) ); // #3f3 #AA0ef #abc
1919
```
2020

21-
There's minor problem here: the pattern found `match:#abc` in `subject:#abcd`. To prevent that we can add `pattern:\b` to the end:
21+
ここで小さな問題があります: パターンは `subject:#abcd` の中で `match:#abc` を見つけます。これを避けるには、末尾に `pattern:\b` を追加します。:
2222

2323
```js run
2424
let reg = /#([a-f0-9]{3}){1,2}\b/gi;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Find color in the format #abc or #abcdef
1+
# #abc または #abcdef の形式で色を検索する
22

3-
Write a regexp that matches colors in the format `#abc` or `#abcdef`. That is: `#` followed by 3 or 6 hexadimal digits.
3+
形式 `#abc` または `#abcdef` で色をマッチする正規表現を書いてください。つまり、`#` の後に3桁または6桁の16進数が続きます。
44

5-
Usage example:
5+
使用例:
66
```js
77
let reg = /your regexp/g;
88

@@ -11,4 +11,4 @@ let str = "color: #3f3; background-color: #AA00ef; and: #abcd";
1111
alert( str.match(reg) ); // #3f3 #AA0ef
1212
```
1313

14-
P.S. Should be exactly 3 or 6 hex digits: values like `#abcd` should not match.
14+
P.S. 正確に 3 または 6 桁の16進数であるべきです。`#abcd` のような値はマッチしません。

5-regular-expressions/09-regexp-groups/3-find-decimal-positive-numbers/solution.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

2-
An integer number is `pattern:\d+`.
2+
整数値は `pattern:\d+`.
33

4-
A decimal part is: `pattern:\.\d+`.
4+
小数点は: `pattern:\.\d+`.
55

6-
Because the decimal part is optional, let's put it in parentheses with quantifier `pattern:'?'`.
6+
小数点は任意なので、量指定子 `pattern:'?'` をもつ括弧の中に置きましょう。
77

8-
Finally we have the regexp: `pattern:\d+(\.\d+)?`:
8+
これで完成です: `pattern:\d+(\.\d+)?`:
99

1010
```js run
1111
let reg = /\d+(\.\d+)?/g;

5-regular-expressions/09-regexp-groups/3-find-decimal-positive-numbers/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Find positive numbers
1+
# 正数を見つける
22

3-
Create a regexp that looks for positive numbers, including those without a decimal point.
3+
小数点のないものも含め正数を探す正規表現を作成してください。
44

5-
An example of use:
5+
使用した例:
66
```js
77
let reg = /your regexp/g;
88

5-regular-expressions/09-regexp-groups/4-find-decimal-numbers/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
A positive number with an optional decimal part is (per previous task): `pattern:\d+(\.\d+)?`.
1+
任意で少数部分をもつ正の数は(前のタスクより): `pattern:\d+(\.\d+)?`.
22

3-
Let's add an optional `-` in the beginning:
3+
先頭に任意の `-` を追加しましょう。:
44

55
```js run
66
let reg = /-?\d+(\.\d+)?/g;

5-regular-expressions/09-regexp-groups/4-find-decimal-numbers/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# Find all numbers
1+
# すべての数値を見つける
22

3-
Write a regexp that looks for all decimal numbers including integer ones, with the floating point and negative ones.
3+
整数、浮動小数点や負数も含むすべての10進数を探す正規表現を書いてください。
44

5-
An example of use:
5+
使用例:
66

77
```js
8-
let reg = /your regexp/g;
8+
let reg = /あなたの正規表現/g;
99

1010
let str = "-1.5 0 2 -123.4.";
1111

5-regular-expressions/09-regexp-groups/5-parse-expression/solution.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
A regexp for a number is: `pattern:-?\d+(\.\d+)?`. We created it in previous tasks.
1+
数値の正規表現は: `pattern:-?\d+(\.\d+)?` です。前のタスクで作ったものです。
22

3-
An operator is `pattern:[-+*/]`. We put a dash `pattern:-` the first, because in the middle it would mean a character range, we don't need that.
3+
演算子は、`pattern:[-+*/]` です。ダッシュ `pattern:-` を先頭に置きます。中央にある場合、ダッシュは文字の範囲を意味しますが、それは必要ないからです。
44

5-
Note that a slash should be escaped inside a JavaScript regexp `pattern:/.../`.
5+
JavaScript の正規表現 `pattern:/.../` の中ではスラッシュをエスケープする必要があることに注意してください。
66

7-
We need a number, an operator, and then another number. And optional spaces between them.
7+
私たちは、数値、演算子、そして別の数値が必要です。そしてそれらの間にスペースがある場合があります。
88

9-
The full regular expression: `pattern:-?\d+(\.\d+)?\s*[-+*/]\s*-?\d+(\.\d+)?`.
9+
完全な正規表現は次のようになります: `pattern:-?\d+(\.\d+)?\s*[-+*/]\s*-?\d+(\.\d+)?`.
1010

11-
To get a result as an array let's put parentheses around the data that we need: numbers and the operator: `pattern:(-?\d+(\.\d+)?)\s*([-+*/])\s*(-?\d+(\.\d+)?)`.
11+
配列として結果を取得するため、必要なデータの周りに括弧を置きましょう: 数値と演算子です: `pattern:(-?\d+(\.\d+)?)\s*([-+*/])\s*(-?\d+(\.\d+)?)`.
1212

13-
In action:
13+
動作:
1414

1515
```js run
1616
let reg = /(-?\d+(\.\d+)?)\s*([-+*\/])\s*(-?\d+(\.\d+)?)/;
1717

1818
alert( "1.2 + 12".match(reg) );
1919
```
2020

21-
The result includes:
21+
結果は次の内容を含みます:
2222

23-
- `result[0] == "1.2 + 12"` (full match)
24-
- `result[1] == "1"` (first parentheses)
25-
- `result[2] == "2"` (second parentheses -- the decimal part `(\.\d+)?`)
23+
- `result[0] == "1.2 + 12"` (完全なマッチ)
24+
- `result[1] == "1"` (最初の括弧)
25+
- `result[2] == "2"` (2番目の括弧 -- 小数部 `(\.\d+)?`)
2626
- `result[3] == "+"` (...)
2727
- `result[4] == "12"` (...)
28-
- `result[5] == undefined` (the last decimal part is absent, so it's undefined)
28+
- `result[5] == undefined` (最後は小数部がないので undefined です)
2929

30-
We need only numbers and the operator. We don't need decimal parts.
30+
必要なのは数値と演算子だけです。小数部だけは不要です。
3131

32-
So let's remove extra groups from capturing by added `pattern:?:`, for instance: `pattern:(?:\.\d+)?`.
32+
なので、`pattern:(?:\.\d+)?` のように、`pattern:?:` を追加することで、キャプチャグループから余分なグループを取り除きましょう。
3333

34-
The final solution:
34+
最終的な解法は次の通りです:
3535

3636
```js run
3737
function parse(expr) {

5-regular-expressions/09-regexp-groups/5-parse-expression/task.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
# Parse an expression
1+
# 式をパースする
22

3-
An arithmetical expression consists of 2 numbers and an operator between them, for instance:
3+
算術式は2つの数字とそれらの間の演算子で構成されます。:
44

55
- `1 + 2`
66
- `1.2 * 3.4`
77
- `-3 / -6`
88
- `-2 - 2`
99

10-
The operator is one of: `"+"`, `"-"`, `"*"` or `"/"`.
10+
演算子は `"+"`, `"-"`, `"*"` または `"/"` のいずれかです。
1111

12-
There may be extra spaces at the beginning, at the end or between the parts.
12+
先頭や末尾、間に余分なスペースがあるかもしれません。
1313

14-
Create a function `parse(expr)` that takes an expression and returns an array of 3 items:
14+
式を取り、3つのアイテムを持つ配列を返す `parse(expr)` を作成してください。
1515

16-
1. The first number.
17-
2. The operator.
18-
3. The second number.
16+
1. 最初の数値
17+
2. 演算子
18+
3. 2番目の数値
1919

20-
For example:
20+
:
2121

2222
```js
2323
let [a, op, b] = parse("1.2 * 3.4");

0 commit comments

Comments
 (0)