regexp: Update formatting

This commit is contained in:
Rico Sta. Cruz 2019-03-24 07:38:52 +08:00
parent aaa1f64e65
commit f79ab86a2c
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A
1 changed files with 38 additions and 33 deletions

View File

@ -5,56 +5,61 @@ layout: 2017/sheet
weight: -1 weight: -1
authors: authors:
- github: rizqyhi - github: rizqyhi
updated: 2018-10-26 updated: 2019-03-24
description: | description: |
Basic cheatsheets for regular expression Basic cheatsheets for regular expression
--- ---
### Character Classes ##
| Pattern | Description | {: .-three-column}
| --- | --- |
| `.` | Any character, except newline | ### Character classes
| `\w` | Word |
| `\d` | Digit | | Pattern | Description |
| `\s` | Whitespace | | ------- | ------------------------------ |
| `\W` | Not word | | `.` | Any character, except newline |
| `\D` | Not digit | | `\w` | Word |
| `\S` | Not whitespace | | `\d` | Digit |
| `[abc]` | Any of a, b, or c | | `\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` | | `[a-e]` | Characters between `a` and `e` |
| `[1-9]` | Digit between `1` and `9` | | `[1-9]` | Digit between `1` and `9` |
### Anchors ### Anchors
| Pattern | Description | | Pattern | Description |
| --- | --- | | ------- | ---------------- |
| `^abc` | Start with `abc` | | `^abc` | Start with `abc` |
| `abc$` | End with `abc` | | `abc$` | End with `abc` |
### Escaped Characters ### Escaped characters
| Pattern | Description | | Pattern | Description |
| --- | --- | | ---------- | -------------------------------------- |
| `\. \* \\` | Escape special character used by regex | | `\. \* \\` | Escape special character used by regex |
| `\t` | Tab | | `\t` | Tab |
| `\n` | Newline | | `\n` | Newline |
| `\r` | Carriage return | | `\r` | Carriage return |
### Groups ### Groups
| Pattern | Description | | Pattern | Description |
| --- | --- | | ------- | ------------- |
| `(abc)` | Capture group | | `(abc)` | Capture group |
### Quantifiers ### Quantifiers
| Pattern | Description | | Pattern | Description |
| --- | --- | | -------- | --------------------- |
| `a*` | Match 0 or more | | `a*` | Match 0 or more |
| `a+` | Match 1 or more | | `a+` | Match 1 or more |
| `a?` | Match 0 or 1 | | `a?` | Match 0 or 1 |
| `a{5}` | Match exactly 5 | | `a{5}` | Match exactly 5 |
| `a{,3}` | Match up to 3 | | `a{,3}` | Match up to 3 |
| `a{3,}` | Match 3 or more | | `a{3,}` | Match 3 or more |
| `a{1,3}` | Match between 1 and 3 | | `a{1,3}` | Match between 1 and 3 |