Skip to main content
DevTools24

Regex Cheatsheet

Vollständige Regex-Referenz mit Mustern, Zeichenklassen, Quantifizierern und mehr. Muster einfach suchen und kopieren.

Character Classes

.Any character except newlinea.c → abc, aXc
\dDigit (0-9)\d{3} → 123
\DNon-digit\D+ → abc
\wWord character (a-z, A-Z, 0-9, _)\w+ → hello_123
\WNon-word character\W → @, #, !
\sWhitespace (space, tab, newline)a\sb → a b
\SNon-whitespace\S+ → hello
[abc]Any of a, b, or c[aeiou] → vowels
[^abc]Not a, b, or c[^0-9] → non-digits
[a-z]Range a to z[A-Za-z] → letters

Anchors

^Start of string/line^Hello → Hello...
$End of string/lineworld$ → ...world
\bWord boundary\bcat\b → cat (not cats)
\BNon-word boundary\Bcat → bobcat

Quantifiers

*0 or morea* → '', a, aa, aaa
+1 or morea+ → a, aa, aaa
?0 or 1 (optional)colou?r → color, colour
{n}Exactly n times\d{4} → 2024
{n,}n or more times\d{2,} → 12, 123, 1234
{n,m}Between n and m times\d{2,4} → 12, 123, 1234
*?0 or more (lazy)a*? → minimal match
+?1 or more (lazy)<.+?> → <b> (not <b>...</b>)

Groups & References

(abc)Capturing group(\d+) → captures digits
(?:abc)Non-capturing group(?:ab)+ → abab
(?<name>abc)Named capturing group(?<year>\d{4})
\1Backreference to group 1(\w)\1 → aa, bb
(a|b)Alternation (a or b)(cat|dog) → cat or dog

Lookahead & Lookbehind

(?=abc)Positive lookahead\d(?=px) → 5 in '5px'
(?!abc)Negative lookahead\d(?!px) → 5 in '5em'
(?<=abc)Positive lookbehind(?<=\$)\d+ → 100 in '$100'
(?<!abc)Negative lookbehind(?<!\$)\d+ → 100 in '€100'

Flags

gGlobal (find all matches)/a/g → all 'a' matches
iCase insensitive/abc/i → ABC, abc, Abc
mMultiline (^ and $ match line breaks)/^line/m
sDotall (. matches newlines)/a.b/s → a\nb
uUnicode support/\u{1F600}/u → emoji

Common Patterns

^[\w.-]+@[\w.-]+\.\w{2,}$Email (basic)user@example.com
^https?://[\w.-]+(?:/[\w.-]*)*$URL (basic)https://example.com/path
^\d{4}-\d{2}-\d{2}$Date (YYYY-MM-DD)2024-01-15
^\+?[\d\s-]{10,}$Phone number (basic)+1 555-123-4567
^#?([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$Hex color#FF5733, #F00
^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$IPv4 address (basic)192.168.1.1

Reguläre Ausdrücke - Technische Details

Reguläre Ausdrücke (Regex) sind Muster zum Abgleichen von Text. Sie werden in Suche, Validierung, Parsing und Textmanipulation in Programmiersprachen und Tools verwendet.

Kommandozeilen-Alternative

// Common patterns\n\\d+       Match digits\n\\w+       Match word chars\n^...$     Start/end anchors\n(a|b)     Alternation\n(?=...)   Positive lookahead