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