OSDN Git Service

Regular updates
[twpd/master.git] / regexp.md
1 ---
2 title: regexp
3 category: Others
4 layout: 2017/sheet
5 weight: -1
6 authors:
7   - github: rizqyhi
8   - github: samtrion
9 updated: 2019-11-14
10 description: |
11   Basic cheatsheets for regular expression
12 ---
13
14 ##
15
16 {: .-three-column}
17
18 ### Character classes
19
20 | Pattern  | Description                          |
21 | -------- | ------------------------------------ |
22 | `.`      | Any character, except newline        |
23 | `\w`     | Word                                 |
24 | `\d`     | Digit                                |
25 | `\s`     | Whitespace                           |
26 | `\W`     | Not word                             |
27 | `\D`     | Not digit                            |
28 | `\S`     | Not whitespace                       |
29 | `[abc]`  | Any of a, b, or c                    |
30 | `[a-e]`  | Characters between `a` and `e`       |
31 | `[1-9]`  | Digit between `1` and `9`            |
32 | `[^abc]` | Any character except `a`, `b` or `c` |
33
34 ### Anchors
35
36 | Pattern | Description      |
37 | ------- | ---------------- |
38 | `^abc`  | Start with `abc` |
39 | `abc$`  | End with `abc`   |
40
41 ### Escaped characters
42
43 | Pattern    | Description                            |
44 | ---------- | -------------------------------------- |
45 | `\. \* \\` | Escape special character used by regex |
46 | `\t`       | Tab                                    |
47 | `\n`       | Newline                                |
48 | `\r`       | Carriage return                        |
49
50 ### Groups
51
52 | Pattern | Description   |
53 | ------- | ------------- |
54 | `(abc)` | Capture group |
55
56 ### Quantifiers
57
58 | Pattern  | Description           |
59 | -------- | --------------------- |
60 | `a*`     | Match 0 or more       |
61 | `a+`     | Match 1 or more       |
62 | `a?`     | Match 0 or 1          |
63 | `a{5}`   | Match exactly 5       |
64 | `a{,3}`  | Match up to 3         |
65 | `a{3,}`  | Match 3 or more       |
66 | `a{1,3}` | Match between 1 and 3 |
67