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 | `[[:print:]]` | Any printable character including spaces |
34 | `[^abc]` | Any character except `a`, `b` or `c` |
38 | Pattern | Description |
39 | ------- | ----------------------- |
40 | `\G` | Start of match |
41 | `^` | Start of string |
42 | `$` | End of string |
43 | `\A` | Start of string |
44 | `\Z` | End of string |
45 | `\z` | Absolute end of string |
46 | `\b` | A word boundry |
47 | `\B` | Non-word boundry |
48 | `^abc` | Start with `abc` |
49 | `abc$` | End with `abc` |
51 ### Escaped characters
53 | Pattern | Description |
54 | ---------- | -------------------------------------- |
55 | `\. \* \\` | Escape special character used by regex |
58 | `\r` | Carriage return |
62 | Pattern | Description |
63 | --------- | ------------------------------ |
64 | `(abc)` | Capture group |
65 | `(a|b)` | Match `a` or `b` |
66 | `(?:abc)` | Match `abc`, but don't capture |
71 | Pattern | Description |
72 | -------- | --------------------- |
73 | `a*` | Match 0 or more |
74 | `a+` | Match 1 or more |
75 | `a?` | Match 0 or 1 |
76 | `a{5}` | Match exactly 5 |
77 | `a{,3}` | Match up to 3 |
78 | `a{3,}` | Match 3 or more |
79 | `a{1,3}` | Match between 1 and 3 |
81 ### Lookahead & Lookbehind
83 | Pattern | Description |
85 | `a(?=b)` | Match `a` in `baby` but not in `bay` |
86 | `a(?!b)` | Match `a` in `Stan` but not in `Stab` |
88 | `(?<=a)b` | Match `b` in `crabs` but not in `cribs` |
89 | `(?<!a)b` | Match `b` in `fib` but not in `fab` |