RegEx: Unterschied zwischen den Versionen
Aus MattWiki
Matt (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
Matt (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
||
Zeile 2: | Zeile 2: | ||
== General Rules == | == General Rules == | ||
{| class="wikitable" | {| class="wikitable" | ||
Zeile 32: | Zeile 22: | ||
| Word and text boundaries || b ^ $ | | Word and text boundaries || b ^ $ | ||
|} | |} | ||
{| class="wikitable" | {| class="wikitable" | ||
|+ style="text-align: left" | Ranges | |+ style="text-align: left" | Ranges | ||
! Range | ! Range !! Example | ||
|- | |- | ||
| Character class range|| [a-c] | | Character class range|| [a-c] | ||
|- | |- | ||
| Inversion of character class range || [^abc] | | Inversion of character class range || [^abc] | ||
|} | |} | ||
{| class="wikitable" | {| class="wikitable" | ||
Zeile 104: | Zeile 89: | ||
Group 1: IMG1000 <br> | Group 1: IMG1000 <br> | ||
Group 2: 1000 | Group 2: 1000 | ||
|- | |||
| Grouping with alternatives || Monday or Tuesday || (Mon|Tues)day || | |||
Match 1: Monday <br> | |||
Group 1: Mon <br> | |||
Match 2: Tuesday <br> | |||
Group 2: Tues | |||
|} | |} | ||
== Online Regex Tools == | == Online Regex Tools == | ||
* https://regexr.com/ | * https://regexr.com/ | ||
* https://regex101.com/ | * https://regex101.com/ | ||
== Tutorials and Guides == | == Tutorials and Guides == |
Version vom 30. August 2021, 16:08 Uhr
Notes for RegEx respectively Regular Expressions and also some useful ressources.
General Rules
Meta Character | Example |
---|---|
Single Character | . |
Character class digit | \d |
Character class character | \w |
Character class whitespace |
\s |
Inversion of character classes (Not) | \D, \W, \S |
Word and text boundaries | b ^ $ |
Range | Example |
---|---|
Character class range | [a-c] |
Inversion of character class range | [^abc] |
Quantifier | Example |
---|---|
Zero or one character | ? |
Zero or more characters (Kleene Star) | * |
One or more characters (Kleene Plus) | + |
Three characters | {3} |
Four to 20 characters | {4,20} |
White Space | Example |
---|---|
Space | _ |
Tab | \t |
New line | \n |
Carriage return | \r |
Any white space character | \s |
Type | Example |
---|---|
Start of line | ^ |
End of line | $ |
Type | String | Expression | Results |
---|---|---|---|
Group Example 1 | IMG1000.png | ^(IMG\d+\.png)$ | IMG1000.png |
Group Example 2 | IMG1000.png | ^(IMG\d+)\.png$ | IMG1000 |
Nested group | IMG1000.png | ^(IMG(\d+))\.png$ |
Group 1: IMG1000 |
Multiple groups | 1920x1080 | (\d+)x(\d+) |
Group 1: IMG1000 |
Grouping with alternatives | Monday or Tuesday | (Mon|Tues)day |
Match 1: Monday |
Online Regex Tools
Tutorials and Guides
Guide (german): https://t3n.de/news/regex-guide-t3n-552858/
Quick Start Cheat Sheet: https://www.rexegg.com/regex-quickstart.html
Advanced tutorial: https://www.rexegg.com/regex-disambiguation.html
Practical tutorial: https://regexone.com/
Regex with JavaScript: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/#regular-expressions