13 Basic cheatsheets for regular expression
21 | Pattern | Description |
22 | -------- | ------------------------------------ |
23 | `.` | Any character, except newline |
29 | `\S` | Not whitespace |
30 | `[abc]` | Any of a, b, or c |
31 | `[a-e]` | Characters between `a` and `e` |
32 | `[1-9]` | Digit between `1` and `9` |
33 | `[^abc]` | Any character except `a`, `b` or `c` |
37 | Pattern | Description |
38 | ------- | ----------------------- |
39 | `\G` | Start of match |
40 | `^` | Start of string |
41 | `$` | End of string |
42 | `\A` | Start of string |
43 | `\Z` | End of string |
44 | `\z` | Absolute end of string |
45 | `\b` | A word boundry |
46 | `\B` | Non-word boundry |
47 | `^abc` | Start with `abc` |
48 | `abc$` | End with `abc` |
50 ### Escaped characters
52 | Pattern | Description |
53 | ---------- | -------------------------------------- |
54 | `\. \* \\` | Escape special character used by regex |
57 | `\r` | Carriage return |
61 | Pattern | Description |
62 | --------- | ------------------------------ |
63 | `(abc)` | Capture group |
64 | `(a|b)` | Match `a` or `b` |
65 | `(?:abc)` | Match `abc`, but don't capture |
70 | Pattern | Description |
71 | -------- | --------------------- |
72 | `a*` | Match 0 or more |
73 | `a+` | Match 1 or more |
74 | `a?` | Match 0 or 1 |
75 | `a{5}` | Match exactly 5 |
76 | `a{,3}` | Match up to 3 |
77 | `a{3,}` | Match 3 or more |
78 | `a{1,3}` | Match between 1 and 3 |
80 ### Lookahead & Lookbehind
82 | Pattern | Description |
84 | `a(?=b)` | Match `a` in `baby` but not in `bay` |
85 | `a(?!b)` | Match `a` in `Stan` but not in `Stab` |
87 | `(?<=a)b` | Match `b` in `crabs` but not in `cribs` |
88 | `(?<!a)b` | Match `b` in `fib` but not in `fab` |