Regex dictionary

A plain guide to regex syntax references: core tokens, how pattern formats differ between engines, what find-and-replace really changes, and when plain text is safer.

A regex dictionary is a syntax reference for regular expressions. It lists tokens such as character classes, quantifiers, anchors, groups and lookarounds, and states what each one matches. It is not a tutorial and it is not a tester. A tutorial builds skills in order. A tester runs a pattern against sample text. A dictionary answers a narrower question: what does this piece of syntax mean, and in which engine? That last part is where references differ most, and it is the main thing to check before relying on one.

Is a regex reference the right tool for your task?

A regex reference is a good fit when you need to read an existing pattern, look up a token you half remember, or build a search or find-and-replace rule for text with a predictable shape. Its main benefit is speed: one lookup usually settles what a token does. The decisive tradeoff is engine variation. JavaScript, Python, Java, .NET, PCRE, POSIX tools and Go's RE2 share most basic syntax but differ on Unicode handling, lookbehind, backreferences, named groups and flags. An entry that is correct for one engine can be silently wrong in another. Prefer a reference that labels each entry by engine, or one written for the engine you actually use.

  • Cases where plain text or a different tool is the better choice:
  • You are searching for a fixed string. Literal search avoids escaping mistakes with characters such as . ( ) [ ] ? * + and |.
  • The input is a nested or quoted format such as HTML, XML, JSON or CSV with quoted fields. A real parser handles structure that regular expressions cannot reliably track.
  • The pattern will be maintained by people who do not read regex. A short plain-language rule or a small function may be easier to keep correct.
  • You need real validation, for example of calendar dates or email deliverability. A pattern can check shape but not meaning.

Core regex syntax at a glance

Token | Meaning | Engine notes
. | Any single character except a newline by default | A dot-all flag (often s) lets it match newlines in most engines
\d | A digit | ASCII 0-9 in JavaScript; Unicode decimal digits by default in Python 3 and .NET; POSIX tools use [[:digit:]] instead
\w | A word character | ASCII letters, digits and underscore in JavaScript; Unicode-aware by default for Python 3 str patterns
\s | A whitespace character | Exactly which characters count varies by engine
[abc] and [^abc] | One character from the set, or one character not in it | Ranges such as [a-z] follow code point order, not alphabetical order in every language
^ and $ | Start and end of the input | With a multiline flag (often m) they also match at line breaks
• ? | Zero or more, one or more, zero or one | Greedy: they take as much as possible, then back off
{n} {n,} {n,m} | Exactly n, at least n, between n and m | Supported widely; basic POSIX syntax requires escaped braces
*? +? ?? | Lazy versions of the quantifiers | Take as little as possible; not available in POSIX regular expressions
(...) | Capturing group | Numbered from 1 by the position of its opening parenthesis
(?:...) | Non-capturing group | Groups without storing a capture
(?<name>...) | Named group | Python's re module uses (?P<name>...)
\1 | Backreference to group 1 | Not supported by Go's RE2 engine
(?=...) and (?!...) | Positive and negative lookahead | Not supported by RE2
(?<=...) and (?<!...) | Positive and negative lookbehind | Many engines require a fixed-length pattern inside; not supported by RE2
a|b | Alternation: a or b | Lowest precedence, so group it when combining with other parts
\b | Word boundary | Depends on the engine's definition of a word character

Whatever reference you use, test the exact pattern in the engine that will run it. A table like this one describes common behavior; it cannot replace a check against your runtime and its flags.

Regex format: how the same pattern is written in different places

Searches for a regex format or a regex formula usually mean the same thing: how to write a pattern. There is no single formula. The core pattern stays similar, but the wrapper around it changes. JavaScript and Perl use slash delimiters with trailing flags. Python, Java and C# take the pattern as a string, which affects how backslashes must be written. Command-line tools add their own dialects. The example below expresses one shape check, four digits, a hyphen, two digits, a hyphen, two digits, in several environments.

JavaScript:  /^\d{4}-\d{2}-\d{2}$/
Python:      re.compile(r"^\d{4}-\d{2}-\d{2}$")
Java:        Pattern.compile("^\\d{4}-\\d{2}-\\d{2}$")
POSIX ERE:   grep -E '^[0-9]{4}-[0-9]{2}-[0-9]{2}$'

This pattern checks shape only. It accepts 2026-13-45, which is not a real date. That is typical of regex validation: it confirms the text looks right, and a separate step must confirm it is valid.

What a regex transformation actually changes

Matching changes nothing. It only reports where a pattern fits. Replacement is different: it rewrites the stored characters, and the result is new text that will be saved, copied and searched as written. This is unlike visual effects such as CSS styling, mirrored display, decorative font substitution or bidirectional display controls, which affect how text looks without, or in addition to, changing what it says. A regex replacement has no presentation layer. What you see in the output is what is stored.

Input:        Lovelace, Ada
Pattern:      ^(\w+),\s*(\w+)$
Replacement:  $2 $1            (JavaScript, .NET, Java)
              \2 \1 or \g<2> \g<1>   (Python re.sub)
Output:       Ada Lovelace

The example works for plain ASCII names, but it shows why engine notes matter. With the input Brontë, Anne, JavaScript's ASCII-only \w stops before the ë, the anchored pattern fails, and the line is left unchanged without any error. Python 3 matches it when ë is a single precomposed character. If the same ë is stored as e plus a combining diaeresis, Python's \w does not match the combining mark either. Normalizing text to a consistent form, such as NFC, before matching removes that difference.

The word reverse causes confusion in this area. Regular expressions do not reverse text. Reverse search in editors means searching backward through a document, and reversing a string is a separate operation. If a workflow reverses text and then applies a pattern, or the other way round, the reversal step must handle characters made of several code points. A naive reversal splits them, as shown below. Terms such as mirror and font refer to visual or character-substitution effects and are outside what a regex reference covers.

s = "cafe\u0301"          # café written as e + combining acute accent
len(s)                    # 5 code points, 4 visible characters
s[::-1]                   # "\u0301efac": the accent no longer sits on the e
re.findall(r".", s)       # 5 matches: the dot sees code points
regex.findall(r"\X", s)   # 4 matches: \X matches whole grapheme clusters

The same issue affects emoji built from several code points, such as sequences joined with a zero-width joiner. In JavaScript without the u flag, the dot matches a single UTF-16 code unit and can split even a single emoji in half. With the u flag it matches one code point, which still splits joined sequences. Where grapheme-aware matching matters, use an engine that supports \X, such as PCRE, Perl or Python's third-party regex module, or segment the text before matching.

Will patterns and results stay usable after copying or sharing?

The output of a regex replacement is ordinary text, so it copies, searches and edits like any other text. The risk sits mostly in the pattern itself. Patterns copied from web pages, documents or chat messages can pick up curly quotes in place of straight ones, non-breaking spaces in place of spaces, or invisible zero-width characters. Any of these makes a pattern fail or match the wrong thing with no visible difference. When a copied pattern behaves strangely, retype the suspect characters or paste it into a tool that reveals invisible characters.

Escaping is the second common break. A pattern copied from a reference written in slash-delimited form needs extra backslashes inside an ordinary Java or C# string, and Python needs raw strings to avoid the same problem. Moving a pattern between engines can also change its meaning without causing an error, as the \w example shows. Treat every copied pattern as untested in its new environment.

Readability is a real limit. Dense patterns are hard for most people to read, and harder still to review. Several engines, including PCRE, Perl, Python, Java and .NET, offer an extended or verbose mode that ignores unescaped whitespace and allows comments, which makes long patterns easier to share and maintain. Where that mode is not available, keep a plain-language description of what the pattern is meant to match next to it in the code or documentation. That description is the plain-text equivalent reviewers and future maintainers will rely on.

Malformed or overly loose patterns can also cause performance problems. Nested quantifiers such as (a+)+ can trigger heavy backtracking on input that almost matches, which is a known cause of slow searches and service outages in backtracking engines. Engines built on automata, such as RE2, avoid this by design but give up backreferences and lookarounds in exchange.

Evidence gaps

No specific regex dictionary, tester or product was supplied for this review, so no product features, privacy practices or accuracy rates are assessed here. The syntax notes above describe documented, general engine behavior. They are not results of a scoped test. No testing with screen readers or other assistive technology was supplied either. How a given screen reader voices regex syntax, or a reference page built around it, was not verified and should be checked directly if it matters for your audience.

Bottom line

A regex dictionary is worth using when it labels behavior by engine and you confirm each pattern in the runtime that will execute it. Regex replacement changes the stored text itself, so check examples that include accented letters, combining marks and emoji before trusting the output. Choose literal search, a proper parser or plain written rules when the text is fixed, structured or must be maintained by people who do not read regex.