Regex-Spickzettel

Interaktive Regex-Referenz mit durchsuchbarem Syntaxleitfaden. Teste Muster mit Live-Matching. Deckt Zeichenklassen, Quantoren, Gruppen und Flags ab.

Showing 39 of 39 entries

Character Classes

10 entries
.

Any character

Matches any single character except newline (unless s flag is set)

Pattern: c.tMatches: "cat", "cut", "c3t"
\d

Digit

Matches any digit character [0-9]

Pattern: \d+Matches: "42", "007"
\D

Non-digit

Matches any character that is not a digit

Pattern: \D+Matches: "abc", "foo!"
\w

Word character

Matches any alphanumeric character or underscore [A-Za-z0-9_]

Pattern: \w+Matches: "hello", "foo_42"
\W

Non-word character

Matches any character that is not a word character

Pattern: \W+Matches: " ", "!@#"
\s

Whitespace

Matches any whitespace character: space, tab, newline, carriage return, form feed

Pattern: \s+Matches: " ", "\t\n"
\S

Non-whitespace

Matches any character that is not whitespace

Pattern: \S+Matches: "hello", "word"
[abc]

Character set

Matches any single character listed inside the brackets

Pattern: [aeiou]Matches: "a", "e", "i", "o", "u"
[^abc]

Negated set

Matches any single character NOT listed inside the brackets

Pattern: [^aeiou]Matches: "b", "c", "d" (not vowels)
[a-z]

Character range

Matches any character in the specified Unicode range. Combine ranges: [a-zA-Z0-9]

Pattern: [a-z]+Matches: "hello", "world"

Anchors

4 entries
^

Start of string

Matches the position at the start of the string (or line with m flag)

Pattern: ^HelloMatches: "Hello world" (start only)
$

End of string

Matches the position at the end of the string (or line with m flag)

Pattern: world$Matches: "Hello world" (end only)
\b

Word boundary

Matches the position between a word character and a non-word character

Pattern: \bcat\bMatches: "cat" but not "catfish"
\B

Non-word boundary

Matches any position that is not a word boundary

Pattern: \Bcat\BMatches: "concatenate" (mid-word)

Quantifiers

8 entries
*

Zero or more (greedy)

Matches the preceding element zero or more times, as many as possible

Pattern: ab*cMatches: "ac", "abc", "abbc"
+

One or more (greedy)

Matches the preceding element one or more times, as many as possible

Pattern: ab+cMatches: "abc", "abbc" (not "ac")
?

Zero or one

Matches the preceding element zero or one time (makes it optional)

Pattern: colou?rMatches: "color", "colour"
{n}

Exactly n

Matches the preceding element exactly n times

Pattern: \d{4}Matches: "2024", "1234"
{n,}

n or more

Matches the preceding element n or more times

Pattern: \d{2,}Matches: "12", "999", "1000"
{n,m}

Between n and m

Matches the preceding element between n and m times (inclusive)

Pattern: \d{2,4}Matches: "12", "123", "1234"
*?

Zero or more (lazy)

Matches the preceding element zero or more times, as few as possible

Pattern: <.+?>Matches: "<b>" in "<b>bold</b>"
+?

One or more (lazy)

Matches the preceding element one or more times, as few as possible

Pattern: "[^"]+?"Matches: Shortest quoted string

Groups

6 entries
(abc)

Capturing group

Groups the expression and captures the matched text. Accessible as \1, \2, or match[1]

Pattern: (\d{4})Matches: Captures year in "2024-01-15"
(?:abc)

Non-capturing group

Groups the expression without creating a capture. Use to apply quantifiers without capturing

Pattern: (?:ab)+Matches: "ab", "abab", "ababab"
(?=abc)

Positive lookahead

Asserts that what follows the current position matches the pattern (zero-width)

Pattern: \d+(?= USD)Matches: "100" in "100 USD"
(?!abc)

Negative lookahead

Asserts that what follows does NOT match the pattern (zero-width)

Pattern: \d+(?! USD)Matches: "42" in "42 EUR"
(?<=abc)

Positive lookbehind

Asserts that what precedes the current position matches the pattern (zero-width)

Pattern: (?<=\$)\d+Matches: "100" in "$100"
(?<!abc)

Negative lookbehind

Asserts that what precedes does NOT match the pattern (zero-width)

Pattern: (?<!\$)\d+Matches: "42" but not "$42"

Flags

6 entries
g

Global

Find all matches rather than stopping after the first match

Pattern: /\d+/gMatches: All numbers in a string
i

Ignore case

Makes the pattern case-insensitive

Pattern: /hello/iMatches: "hello", "HELLO", "Hello"
m

Multiline

Makes ^ match the start of each line and $ match the end of each line

Pattern: /^\w+/mMatches: First word of each line
s

DotAll

Makes . match any character including newline characters

Pattern: /a.b/sMatches: "a\nb" across newlines
u

Unicode

Enables full Unicode matching; required for \p{...} property escapes and 4-byte Unicode code points

Pattern: /\p{L}+/uMatches: Any Unicode letter
y

Sticky

Matches only from the position indicated by lastIndex; does not advance past it

Pattern: /\d+/yMatches: Only at exact lastIndex position

Special

5 entries
|

Alternation

Matches either the expression before or after the pipe. Acts like OR

Pattern: cat|dogMatches: "cat" or "dog"
\1

Backreference

Matches the same text that was matched by capturing group 1. \2 for group 2, etc.

Pattern: (\w+)\s\1Matches: "the the", "ha ha"
\n

Newline

Matches a newline character (line feed, LF)

Pattern: \r?\nMatches: Unix or Windows line endings
\t

Tab

Matches a horizontal tab character

Pattern: \t+Matches: Tab-indented lines
\\

Literal backslash

Matches a literal backslash character. Backslash must be escaped as \\

Pattern: C:\\\w+Matches: "C:\Users" in file paths

Quick Test

— paste a pattern and see matches highlighted
//g

So verwenden Sie Regex-Spickzettel

  1. 1Durchsuche Regex-Syntax nach Kategorie.
  2. 2Suche nach bestimmten Mustern oder Konzepten.
  3. 3Teste dein Regex mit dem Live-Matcher.
  4. 4Kopiere ein beliebiges Muster zur Verwendung in deinem Code.
ZenovayAnalytics

Analytics, für Gründer gebaut.

  • Besucher-Tracking in Echtzeit
  • Datenschutz zuerst, kein Cookie-Banner
  • In zwei Minuten eingerichtet
Zenovay entdecken

Häufig gestellte Fragen

Was ist ein regulärer Ausdruck (Regex)?
Ein regulärer Ausdruck ist eine Zeichenfolge, die ein Suchmuster definiert. Regex wird für Zeichenkettenabgleich, Validierung, Suchen und Ersetzen sowie Textextraktion verwendet. Es wird in praktisch jeder Programmiersprache unterstützt.
Was sind die verschiedenen Regex-Varianten?
Hauptvarianten: PCRE (PHP, Python re), JavaScript (ECMAScript), .NET, Java, POSIX. Sie unterscheiden sich in Funktionen wie Lookbehind, benannte Gruppen und Unicode-Unterstützung. JavaScript Regex hat Funktionen wie benannte Gruppen und Lookbehind in ES2018 hinzugefügt.
Was ist gieriges vs. faules Matching?
Gierige Quantoren (*, +, ?) stimmen mit so viel wie möglich überein. Faule (nicht-gierige) Quantoren (*?, +?, ??) stimmen mit so wenig wie möglich überein. Beispiel: Für '<b>bold</b>' stimmt /<.*>/ mit '<b>bold</b>' (gierig) überein, während /<.*?>/ mit '<b>' (faul) übereinstimmt.
Was sind Lookahead und Lookbehind?
Lookahead (?=...) und Lookbehind (?<=...) sind Assertions mit Breite Null, die ohne Verbrauch von Zeichen übereinstimmen. Positiver Lookahead: \d(?=px) stimmt mit Ziffern überein, gefolgt von 'px'. Negatives Lookbehind: (?<!\$)\d+ stimmt mit Zahlen überein, denen kein '$' vorangeht.
Was sind häufige Regex-Fehler?
Nicht das Escaping von Sonderzeichen (. passt auf jeden Charakter, nicht auf einen Punkt). Katastrophales Backtracking mit verschachtelten Quantoren. Verwendung von .* wenn ein spezifischeres Muster funktionieren würde. Keine Verankerung von Mustern (Vergessen von ^ und $). Verwendung von Regex zum Analysieren von HTML/XML statt eines richtigen Parsers.