You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: book/en-us/06-regex.md
+21-21Lines changed: 21 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -34,32 +34,32 @@ and lowercase letters, all numbers, all punctuation, and some other symbols.
34
34
35
35
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:
|`$`| 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.|
50
50
51
51
### Quantifiers
52
52
53
53
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:
|`*`| 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. |
63
63
64
64
With these two tables, we can usually read almost all regular expressions.
0 commit comments