OSDN Git Service

Regular updates
[twpd/master.git] / regexp.md
index 60e2e7a..30bcd8a 100644 (file)
--- a/regexp.md
+++ b/regexp.md
@@ -5,9 +5,10 @@ layout: 2017/sheet
 weight: -1
 authors:
   - github: rizqyhi
+  - github: izzergh
   - github: kolapsys
   - github: samtrion
-updated: 2019-11-14
+updated: 2020-03-10
 description: |
   Basic cheatsheets for regular expression
 ---
@@ -17,19 +18,20 @@ description: |
 
 ### Character classes
 
-| Pattern  | Description                          |
-| -------- | ------------------------------------ |
-| `.`      | Any character, except newline        |
-| `\w`     | Word                                 |
-| `\d`     | Digit                                |
-| `\s`     | Whitespace                           |
-| `\W`     | Not word                             |
-| `\D`     | Not digit                            |
-| `\S`     | Not whitespace                       |
-| `[abc]`  | Any of a, b, or c                    |
-| `[a-e]`  | Characters between `a` and `e`       |
-| `[1-9]`  | Digit between `1` and `9`            |
-| `[^abc]` | Any character except `a`, `b` or `c` |
+| Pattern       | Description                              |
+| ------------- | ---------------------------------------- |
+| `.`           | Any character, except newline            |
+| `\w`          | Word                                     |
+| `\d`          | Digit                                    |
+| `\s`          | Whitespace                               |
+| `\W`          | Not word                                 |
+| `\D`          | Not digit                                |
+| `\S`          | Not whitespace                           |
+| `[abc]`       | Any of a, b, or c                        |
+| `[a-e]`       | Characters between `a` and `e`           |
+| `[1-9]`       | Digit between `1` and `9`                |
+| `[[:print:]]` | Any printable character including spaces |
+| `[^abc]`      | Any character except `a`, `b` or `c`     |
 
 ### Anchors
 
@@ -57,11 +59,12 @@ description: |
 
 ### Groups
 
-| Pattern   | Description                    |
-| --------- | ------------------------------ |
-| `(abc)`   | Capture group                  |
-| `(a|b)`   | Match `a` or `b`               |
-| `(?:abc)` | Match `abc`, but don't capture |
+| Pattern   | Description                                             |
+| --------- | ------------------------------------------------------- |
+| `(abc)`   | Capture group                                           |
+| `(a|b)`   | Match `a` or `b`                                        |
+| `(?:abc)` | Match `abc`, but don't capture                          |
+| `\1`      | Subsituted with text matched of the 1st capturing group |
 
 
 ### Quantifiers
@@ -76,3 +79,12 @@ description: |
 | `a{3,}`  | Match 3 or more       |
 | `a{1,3}` | Match between 1 and 3 |
 
+### Lookahead & Lookbehind
+
+| Pattern      | Description                               |
+| ---          | ---                                       |
+| `a(?=b)`     | Match `a` in `baby` but not in `bay`      |
+| `a(?!b)`     | Match `a` in `Stan` but not in `Stab`     |
+| ---          | ---                                       |
+| `(?<=a)b`    | Match `b` in `crabs` but not in `cribs`   |
+| `(?<!a)b`    | Match `b` in `fib` but not in `fab`       |