Alles erweitert

This commit is contained in:
2026-09-14 14:00:27 +02:00
parent 12515fe2eb
commit b331e333ca
9 changed files with 33230 additions and 109 deletions
+154 -17
View File
@@ -2,29 +2,35 @@
A regular expression specifies a set of strings that matches it. This cheat sheet is based off Python 3's Regular Expressions (http://docs.python.org/3/library/re.html) but is designed for searches within Sublime Text.
https://gist.github.com/IsaacCisneros/d7f3cf4bf6c0573d0570
https://ahkde.github.io/docs/v1/misc/RegEx-QuickRef.htm
https://serverdiscounter.com/blog/2026-01-26-regex-grundlagen
## Special Characters
| | |
| --- | ----------------------------------------------------------- |
| `\` | Escapes special characters or signals a special sequence. |
| `.` | Matches any single character except a newline. |
| `^` | Matches the start of the string. |
| `$` | Matches the end of the string​ |
| `*` | Greedily matches 0 or more repetitions of the preceding RE. |
| | |
| | |
| | |
| | |
| | |
| ---- | ------------------------------------------------------------------------------- |
| `\` | Escapet Sonderzeichen oder kennzeichnet eine spezielle Sequenz |
| `.` | Entspricht einem beliebigen einzelnen Zeichen mit Ausnahme eines Zeilenumbruchs |
| `^` | Matches the start of the string. |
| `$` | Matches the end of the string​ |
| `*` | Greedily matches 0 or more repetitions of the preceding RE. |
| `*?` | Matches 0 or more repetitions of the preceding RE. |
| `+` | Greedily matches 1 or more repetitions of the preceding RE. |
| `+?` | Matches 1 or more repetitions of the preceding RE. |
| ? | Greedily matches 0 or 1 repetitions of the preceding RE. |
| ?? | Matches 0 or 1 repetitions of the preceding RE. |
​
`*?` Matches 0 or more repetitions of the preceding RE.
+ Greedily matches 1 or more repetitions of the preceding RE.
+
+? Matches 1 or more repetitions of the preceding RE.
? Greedily matches 0 or 1 repetitions of the preceding RE.
?? Matches 0 or 1 repetitions of the preceding RE.
A|B Matches A, if A is unmatched then matches B, where A and B are arbitrary REs.
{m} Matches exactly m many repetitions of the previous RE.
{m,n} Greedily matches from m many to n many repetitions of the previous RE.
@@ -77,3 +83,134 @@ A regular expression specifies a set of strings that matches it. This cheat shee
).
\t Matches the ASCII Horizontal Tab.
\v Matches the ASCII Vertical Tab ( ).
#########################
### Regular Expression Cheat Sheet with Examples
Regular Expressions (regex) are patterns used to match strings in text. Below is a cheat sheet with common regex patterns and examples.
---
### **1. Anchors**
| Pattern | Description | Example | Matches |
| ------- | ------------------- | -------- | -------------- |
| `^` | Start of the string | `^Hello` | `Hello world!` |
| `$` | End of the string | `world$` | `Hello world!` |
---
### **2. Quantifiers**
| Pattern | Description | Example | Matches |
| ------- | ------------------------------- | --------- | ------------------------ |
| `*` | 0 or more | `a*` | `aaa`, `b` |
| `+` | 1 or more | `a+` | `aaa`, but not `b` |
| `?` | 0 or 1 | `colou?r` | `color`, `colour` |
| `{n}` | Exactly `n` occurrences | `a{3}` | `aaa`, but not `aa` |
| `{n,}` | At least `n` occurrences | `a{2,}` | `aa`, `aaa` |
| `{n,m}` | Between `n` and `m` occurrences | `a{2,3}` | `aa`, `aaa`, but not `a` |
---
### **3. Character Classes**
| Pattern | Description | Example | Matches |
| ------- | ---------------------------------------- | ------- | --------------- |
| `.` | Any character except newline | `a.b` | `acb`, `a9b` |
| `\d` | Any digit (0-9) | `\d+` | `123`, `9` |
| `\D` | Any non-digit | `\D+` | `abc`, `@#` |
| `\w` | Any word character (alphanumeric or `_`) | `\w+` | `hello_123` |
| `\W` | Any non-word character | `\W+` | `@!`, ` #` |
| `\s` | Any whitespace | `\s+` | ` `, `\t`, `\n` |
| `\S` | Any non-whitespace | `\S+` | `abc`, `123` |
---
### **4. Logical OR and Grouping**
| Pattern | Description | Example | Matches |
| ------- | ----------- | ----------------------- | ------- |
| `a | b` | Match either `a` or `b` | `cat |
| `(ab | cd)` | Grouping | `(ab |
---
### **5. Escape Characters**
| Pattern | Description | Example | Matches |
| ------- | ----------- | --------- | ------- |
| `\.` | Literal dot | `a\.b` | `a.b` |
| `\[` | Literal `[` | `\[abc\]` | `[abc]` |
---
### **6. Ranges**
| Pattern | Description | Example | Matches |
| -------------- | --------------------------- | -------- | ------------ |
| `[a-z]` | Lowercase letters | `[a-z]+` | `abc`, `xyz` |
| `[A-Z]` | Uppercase letters | `[A-Z]+` | `ABC`, `XYZ` |
| `[0-9]` | Digits | `[0-9]+` | `123`, `456` |
| `[a-zA-Z0-9_]` | Alphanumeric and underscore | `\w+` | `hello123_` |
---
### **7. Special Sequences**
| Pattern | Description | Example | Matches |
| ---------- | ------------------- | ------------- | ----------------- |
| `(?=...)` | Positive lookahead | `foo(?=bar)` | `foo` in `foobar` |
| `(?!...)` | Negative lookahead | `foo(?!bar)` | `foo` in `foobaz` |
| `(?<=...)` | Positive lookbehind | `(?<=foo)bar` | `bar` in `foobar` |
| `(?<!...)` | Negative lookbehind | `(?<!foo)bar` | `bar` in `bazbar` |
---
### **8. Common Patterns**
| Use Case | Regex | Example |
| ----------------------- | ------------------------------------------------ | --------------------- |
| Match email | `[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}` | `user@example.com` |
| Match URL | `https?://[^\s]+` | `https://example.com` |
| Match phone number | `\d{3}-\d{3}-\d{4}` | `123-456-7890` |
| Match date (YYYY-MM-DD) | `\d{4}-\d{2}-\d{2}` | `2024-12-13` |
---
### **9. Flags**
| Flag | Description | Example |
| ---- | ---------------- | ------------------------------ |
| `i` | Case-insensitive | `/hello/i` matches `Hello` |
| `g` | Global match | `/hello/g` matches all `hello` |
| `m` | Multiline | `/^hello/m` matches per line |
---
### **10. Examples in Code**
#### Python Example:
```python
import re
# Match an email
pattern = r"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}"
email = "contact@example.com"
print(re.match(pattern, email)) # Output: <re.Match object>
```
#### JavaScript Example:
```javascript
// Match a URL
let pattern = /https?:\/\/[^\s]+/g;
let text = "Visit https://example.com for more info.";
console.log(text.match(pattern)); // Output: [ 'https://example.com' ]
```
[regular-expressions-v2.pdf](regular-expressions-v2.pdf)
[regular-expressions-cheat-sheet-v1.pdf](regular-expressions-cheat-sheet-v1.pdf)
[regex-cheatsheet.pdf](regex-cheatsheet.pdf)