Skip to content

Commit b224045

Browse files
committed
book: use compact table
Updates changkun#227
1 parent d740ee8 commit b224045

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

book/en-us/06-regex.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,32 @@ and lowercase letters, all numbers, all punctuation, and some other symbols.
3434

3535
A special character is a character with special meaning in a regular expression and is also the core matching syntax of a regular expression. See the table below:
3636

37-
| Symbol | Description |
38-
| :----------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
39-
| `$` | Matches the end position of the input string. |
40-
| `(`,`)` | Marks the start and end of a subexpression. Subexpressions can be obtained for later use. |
41-
| `*` | Matches the previous subexpression zero or more times. |
42-
| `+` | Matches the previous subexpression one or more times. |
43-
| `.` | Matches any single character except the newline character `\n`. |
44-
| `[` | Marks the beginning of a bracket expression. |
45-
| `?` | Matches the previous subexpression zero or one time, or indicates a non-greedy qualifier. |
46-
| `\` | Marks the next character as either a special character, or a literal character, or a backward reference, or an octal escape character. For example, `n` Matches the character `n`. `\n` matches newline characters. The sequence `\\` Matches the `'\'` character, while `\(` matches the `'('` character. |
47-
| `^` | Matches the beginning of the input string, unless it is used in a square bracket expression, at which point it indicates that the set of characters is not accepted. |
48-
| `{` | Marks the beginning of a qualifier expression. |
49-
| `\|` | Indicates a choice between the two. |
37+
| Symbol | Description |
38+
|:----------------:|:---|
39+
| `$` | Matches the end position of the input string.|
40+
| `(`,`)` | Marks the start and end of a subexpression. Subexpressions can be obtained for later use.|
41+
| `*` | Matches the previous subexpression zero or more times. |
42+
| `+` | Matches the previous subexpression one or more times.|
43+
| `.` | Matches any single character except the newline character `\n`.|
44+
| `[` | Marks the beginning of a bracket expression.|
45+
| `?` | Matches the previous subexpression zero or one time, or indicates a non-greedy qualifier.|
46+
| `\` | Marks the next character as either a special character, or a literal character, or a backward reference, or an octal escape character. For example, `n` Matches the character `n`. `\n` matches newline characters. The sequence `\\` Matches the `'\'` character, while `\(` matches the `'('` character. |
47+
| `^` | Matches the beginning of the input string, unless it is used in a square bracket expression, at which point it indicates that the set of characters is not accepted.|
48+
| `{` | Marks the beginning of a qualifier expression.|
49+
| `\|` | Indicates a choice between the two.|
5050

5151
### Quantifiers
5252

5353
The qualifier is used to specify how many times a given component of a regular expression must appear to satisfy the match. See the table below:
5454

55-
| Symbol | Description |
56-
| :-------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
57-
| `*` | matches the previous subexpression zero or more times. For example, `foo*` matches `fo` and `foooo`. `*` is equivalent to `{0,}`. |
58-
| `+` | matches the previous subexpression one or more times. For example, `foo+` matches `foo` and `foooo` but does not match `fo`. `+` is equivalent to `{1,}`. |
59-
| `?` | matches the previous subexpression zero or one time. For example, `Your(s)?` can match `Your` in `Your` or `Yours`. `?` is equivalent to `{0,1}`. |
60-
| `{n}` | `n` is a non-negative integer. Matches the determined `n` times. For example, `o{2}` cannot match `o` in `for`, but can match two `o` in `foo`. |
61-
| `{n,}` | `n` is a non-negative integer. Match at least `n` times. For example, `o{2,}` cannot match `o` in `for`, but matches all `o` in `foooooo`. `o{1,}` is equivalent to `o+`. `o{0,}` is equivalent to `o*`. |
62-
| `{n,m}` | `m` and `n` are non-negative integers, where `n` is less than or equal to `m`. Matches at least `n` times and matches up to `m` times. For example, `o{1,3}` will match the first three `o` in `foooooo`. `o{0,1}` is equivalent to `o?`. Note that there can be no spaces between the comma and the two numbers. |
55+
| Symbol | Description |
56+
|:-------:|:-----|
57+
| `*` | matches the previous subexpression zero or more times. For example, `foo*` matches `fo` and `foooo`. `*` is equivalent to `{0,}`.|
58+
| `+` | matches the previous subexpression one or more times. For example, `foo+` matches `foo` and `foooo` but does not match `fo`. `+` is equivalent to `{1,}`.|
59+
| `?` | matches the previous subexpression zero or one time. For example, `Your(s)?` can match `Your` in `Your` or `Yours`. `?` is equivalent to `{0,1}`.|
60+
| `{n}` | `n` is a non-negative integer. Matches the determined `n` times. For example, `o{2}` cannot match `o` in `for`, but can match two `o` in `foo`.|
61+
| `{n,}` | `n` is a non-negative integer. Match at least `n` times. For example, `o{2,}` cannot match `o` in `for`, but matches all `o` in `foooooo`. `o{1,}` is equivalent to `o+`. `o{0,}` is equivalent to `o*`.|
62+
| `{n,m}` | `m` and `n` are non-negative integers, where `n` is less than or equal to `m`. Matches at least `n` times and matches up to `m` times. For example, `o{1,3}` will match the first three `o` in `foooooo`. `o{0,1}` is equivalent to `o?`. Note that there can be no spaces between the comma and the two numbers. |
6363

6464
With these two tables, we can usually read almost all regular expressions.
6565

0 commit comments

Comments
 (0)