Regex Metacharacter Reference

All regex special characters with meaning and example.

Searchable reference of regular-expression metacharacters — anchors, quantifiers, character classes, groups and lookarounds — that work across PCRE, JavaScript and Python.

What is a regex metacharacter?

A metacharacter is a character that has special meaning in a regular expression rather than matching itself literally. Examples include the dot, star, caret and dollar. To match one literally you escape it with a backslash, for example \. matches a real dot.

Every regex special character in one place

Regular expressions build matching power out of a small set of metacharacters: characters that mean something other than themselves. This reference lists the anchors, quantifiers, character classes, groups and lookaround assertions that are common to the three most-used engines — PCRE, JavaScript and Python — with a plain-language meaning and a working example for each.

How it works

A regex engine reads your pattern left to right. Literal characters match themselves; metacharacters change the matching rules. Quantifiers like *, +, ? and {n,m} repeat the preceding token. Anchors like ^ and $ match positions rather than characters. Character classes [...] match any one character from a set, and groups (...) capture or scope sub-patterns.

^\d{3}-\d{4}$        matches 123-4567
colou?r              matches color and colour
(?<=£)\d+(?:\.\d{2})? matches the number after a £ sign

To match a metacharacter literally, escape it with a backslash: \. matches a real dot, \( matches a real parenthesis.

Tips and gotchas

  • Alternation | has the lowest precedence — wrap it in a group, like gr(a|e)y, to limit its scope.
  • A caret means start-of-string outside a class but negation as the first character inside one: [^0-9].
  • Make quantifiers lazy with a trailing ? when greedy matching swallows too much text.
  • Named groups differ: JavaScript and PCRE use (?<name>...), Python uses (?P<name>...). The filter notes flag these engine differences.