Skip to content

Commit f6e91c1

Browse files
committed
Translate 5-regular-expressions/11-regexp-alternation/article.md
1 parent e7923ba commit f6e91c1

File tree

1 file changed

+28
-28
lines changed
  • 5-regular-expressions/11-regexp-alternation

1 file changed

+28
-28
lines changed

5-regular-expressions/11-regexp-alternation/article.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# Alternation (OR) |
1+
# 論理和指定子(Alternation) (OR) |
22

3-
Alternation is the term in regular expression that is actually a simple "OR".
3+
論理和指定子は、実際には単純な "OR" である正規表現の用語です。
44

5-
In a regular expression it is denoted with a vertical line character `pattern:|`.
5+
正規表現では、縦線の文字 `pattern:|` で表現されます。
66

77
[cut]
88

9-
For instance, we need to find programming languages: HTML, PHP, Java or JavaScript.
9+
例えば、プログラム言語を探す必要があるとします: HTML, PHP, Java, または JavaScript です。
1010

11-
The corresponding regexp: `pattern:html|php|java(script)?`.
11+
対応する正規表現は次の通りです: `pattern:html|php|java(script)?`.
1212

13-
A usage example:
13+
利用例:
1414

1515
```js run
1616
let reg = /html|php|css|java(script)?/gi;
@@ -20,50 +20,50 @@ let str = "First HTML appeared, then CSS, then JavaScript";
2020
alert( str.match(reg) ); // 'HTML', 'CSS', 'JavaScript'
2121
```
2222

23-
We already know a similar thing -- square brackets. They allow to choose between multiple character, for instance `pattern:gr[ae]y` matches `match:gray` or `match:grey`.
23+
私たちは既に同様のことを知っています -- 角括弧です。`pattern:gr[ae]y` `match:gray` または `match:grey` にマッチするように、複数の文字から選択することができます。
2424

25-
Alternation works not on a character level, but on expression level. A regexp `pattern:A|B|C` means one of expressions `A`, `B` or `C`.
25+
論理和指定子は文字レベルで動作するのではなく、式のレベルで動作します。正規表現 `pattern:A|B|C` `A`, `B` または `C` の式のいずれか、を意味します。
2626

27-
For instance:
27+
:
2828

29-
- `pattern:gr(a|e)y` means exactly the same as `pattern:gr[ae]y`.
30-
- `pattern:gra|ey` means "gra" or "ey".
29+
- `pattern:gr(a|e)y` はまさに `pattern:gr[ae]y` と同じ意味です。
30+
- `pattern:gra|ey` "gra" または "ey" を意味します。
3131

32-
To separate a part of the pattern for alternation we usually enclose it in parentheses, like this: `pattern:before(XXX|YYY)after`.
32+
論理和指定子では、パターンの一部を区切るには通常次のようにカッコで囲みます。: `pattern:before(XXX|YYY)after`.
3333

34-
## Regexp for time
34+
## 時間の正規表現
3535

36-
In previous chapters there was a task to build a regexp for searching time in the form `hh:mm`, for instance `12:00`. But a simple `pattern:\d\d:\d\d` is too vague. It accepts `25:99` as the time.
36+
前のチャプターで、`12:00` のような形式 `hh:mm` の時間を探す正規表現を構築するタスクがありました。しかし、単純な `pattern:\d\d:\d\d` はあまりにも要領を得ません。これは `25:99` も時間として許容します。
3737

38-
How can we make a better one?
38+
どうすればより優れた正規表現を作れるでしょうか?
3939

40-
We can apply more careful matching:
40+
その方法として、私たちはより慎重なマッチングを適用することができます:
4141

42-
- The first digit must be `0` or `1` followed by any digit.
43-
- Or `2` followed by `pattern:[0-3]`
42+
- 最初の数字は `0` `1` で、その後に任意の数値が続く必要があります。
43+
- もしくは `2` でその後に `pattern:[0-3]` が続きます。
4444

45-
As a regexp: `pattern:[01]\d|2[0-3]`.
45+
正規表現としてはこのようになります: `pattern:[01]\d|2[0-3]`.
4646

47-
Then we can add a colon and the minutes part.
47+
その後、コロンと分の部分を追加します。
4848

49-
The minutes must be from `0` to `59`, in the regexp language that means the first digit `pattern:[0-5]` followed by any other digit `\d`.
49+
分 は `0` から `59` までである必要があり、正規表現では最初の数字 `pattern:[0-5]` でその後に他の数字 `\d` が続くことを意味します。
5050

51-
Let's glue them together into the pattern: `pattern:[01]\d|2[0-3]:[0-5]\d`.
52-
53-
We're almost done, but there's a problem. The alternation `|` is between the `pattern:[01]\d` and `pattern:2[0-3]:[0-5]\d`. That's wrong, because it will match either the left or the right pattern:
51+
パターンにそれらを引っ付けましょう: `pattern:[01]\d|2[0-3]:[0-5]\d`.
5452

53+
ほとんど完了していますが、まだ問題があります。論理和指定子 `|``pattern:[01]\d``pattern:2[0-3]:[0-5]\d` の間です。これだと左右どちらかのパターンがマッチするすることになるので間違いです。
5554

5655
```js run
5756
let reg = /[01]\d|2[0-3]:[0-5]\d/g;
5857

59-
alert("12".match(reg)); // 12 (matched [01]\d)
58+
alert("12".match(reg)); // 12 ([01]\d にマッチ)
6059
```
6160

62-
That's rather obvious, but still an often mistake when starting to work with regular expressions.
61+
それはかなり明らかではありますが、正規表現で作業を開始するときには依然としてよく起きるミスです。
62+
63+
時間の部分 `[01]\d` OR `2[0-3]` へ正確に論理和指定子を適用するために括弧が必要です。
6364

64-
We need to add parentheses to apply alternation exactly to hours: `[01]\d` OR `2[0-3]`.
6565

66-
The correct variant:
66+
正しいバリアントです:
6767

6868
```js run
6969
let reg = /([01]\d|2[0-3]):[0-5]\d/g;

0 commit comments

Comments
 (0)