Home › Developer Tools › Regex Explainer

Regex Explainer

Paste a regular expression to see what it really does: every token explained in plain English, a railroad diagram of the pattern, notes on its flags, warnings about common mistakes and a live test box.

Last updated:

Railroad diagram

Token-by-token explanation

Flag notes

    Copy as

    Advertisement
    Advertisement

    How to use the Regex Explainer

    1. Paste your regex into the box, either bare (\d{3}-\d{4}) or as a literal with slashes and flags (/\d+/g).
    2. Read the summary and token list. Each row shows a piece of the pattern and what it matches; groups and alternatives are indented.
    3. Follow the railroad diagram from the left dot to the right circle: boxes are things to match, branches are alternatives and loops are repetitions.
    4. Check the flag notes and any warnings, then toggle flags to see how the meaning changes.
    5. Try it on your own text in the test box to confirm the matches and captured groups.

    Regex tokens at a glance

    TokenMeaningExample
    .Any character except a line break (any character with the s flag)a.c matches "abc", "a-c"
    \d \w \sDigit, word character (A–Z, a–z, 0–9, _), whitespace\d\d matches "42"
    \D \W \SThe opposites: non-digit, non-word, non-whitespace\S+ matches a word with punctuation
    [abc] [a-z] [^0-9]One character from a set, a range, or not in the set[aeiou] matches one vowel
    ^ $Start and end of the string (of each line with m)^Hi only at the start
    \bWord boundary\bcat\b matches "cat" but not "category"
    * + ?0 or more, 1 or more, 0 or 1 (optional)colou?r matches both spellings
    {3} {2,5} {2,}Exactly 3, 2 to 5, 2 or more\d{4} matches a year
    *? +?Lazy versions: as few as possible<.+?> matches one tag
    (…) (?<name>…)Capturing group, named group(?<year>\d{4})
    (?:…)Group without capturing(?:ab)+
    a|bAlternation: a or bcat|dog
    (?=…) (?!…)Lookahead: followed by / not followed by\d+(?=px) matches "12" in "12px"
    (?<=…) (?<!…)Lookbehind: preceded by / not preceded by(?<=\$)\d+ matches "5" in "$5"
    \1 \k<name>Backreference: the same text a group matched(\w)\1 matches "ll" in "hello"
    \p{L}Unicode property, here any letter (needs the u flag)\p{L}+ matches "Grüße"

    Reading an unfamiliar regex step by step

    Long patterns become readable once you split them into parts. Look for the anchors first (^, $, \b), because they tell you whether the pattern must match the whole input or can appear anywhere. Next find the groups, since parentheses show what is captured and what a quantifier applies to. Then read each part from left to right, attaching every quantifier to the single token or group directly before it: in ab+ only the b repeats, in (ab)+ the pair repeats.

    Character classes are the most common source of confusion. Inside square brackets most symbols lose their special meaning, so [.] is a literal dot, but ^ at the start negates the class and - between two characters makes a range. When in doubt, escape it with a backslash.

    Frequently asked questions

    Which regex flavor does the explainer use?

    It follows JavaScript (ECMAScript) syntax, which is also very close to what most languages use for the common features: character classes, quantifiers, groups, lookahead and backreferences. Features that exist only in PCRE, Python or .NET, such as atomic groups, possessive quantifiers, inline (?i) flags and \A or \Z, are recognised and flagged as not supported in JavaScript.

    How do I read a railroad diagram?

    Start at the filled dot on the left and follow the lines to the circle on the right. Every box you pass must match in order. Where the line splits into branches, any one branch can match (alternation). A line that skips over a box means it is optional, and a line looping back underneath means it can repeat, with the number of repetitions written below.

    What is the difference between greedy and lazy quantifiers?

    Greedy quantifiers (*, +, {n,m}) match as much as possible and then give characters back if the rest of the pattern fails. Lazy quantifiers (*?, +?, {n,m}?) match as little as possible and take more only when needed. For "a" "b", the pattern ".*" matches the whole text while ".*?" matches each quoted part separately.

    What does catastrophic backtracking mean?

    Patterns with nested repetition, such as (a+)+ or (\w+\s?)*, can try an exponential number of ways to split the text when a match fails. On long inputs this freezes the program. The explainer warns when it sees nested unbounded quantifiers; make the inner part more specific or use a single quantifier instead.

    Why does ^ or $ not match each line?

    By default ^ and $ match only at the start and end of the whole string. Add the m (multiline) flag to make them match at the start and end of every line.

    Is my pattern or text uploaded?

    No. Parsing, explaining, drawing the diagram and testing all happen in JavaScript in your browser.

    Are all the tools on FreeToolCabin tested for quality and accuracy?

    Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

    Related tools

    Regex TesterTest and debug regular expressions live.Regex GeneratorBuild regular expressions visually from blocks or presets (email, date, phone) and test them live.Regex Cheat Sheet75+ ready-to-use regex patterns for emails, URLs, IPs and dates, each with a live test box.CSS Selector TesterTest CSS selectors on your HTML: highlighted matches, match count and specificity.Online Python CompilerRun Python 3 in your browser with input(), numpy, pandas, charts and share links.JSON EditorEdit JSON in a tree and as code side by side: add, rename, drag, change types, undo and download.Unzip FilesOpen and extract ZIP files online.RAR & 7z ExtractorOpen RAR, 7z and other archives online and extract files.File Info ViewerCheck file size, type, date and MD5/SHA hashes.SQLite ViewerOpen .db and .sqlite files in your browser, browse tables and run SQL queries.DOCX ViewerOpen and read Word .docx files in your browser, then print or save them as HTML.EPUB ReaderOpen and read EPUB e-books in your browser with pages, a table of contents and font controls.What Is My BrowserSee your browser, version, OS, engine, screen and which web features it supports.Font ViewerPreview TTF, OTF, WOFF and WOFF2 fonts with sample text, waterfall, glyphs and metadata.Markdown EditorWrite Markdown with a toolbar, live split preview, autosave and .md or HTML export.JavaScript Keycode FinderPress any key to see its JavaScript key, code, keyCode, which, location and modifiers.QR Code ScannerScan QR codes with your camera or from an image and safely read the link or text.RAID CalculatorUsable capacity, efficiency and fault tolerance for RAID 0, 1, 5, 6, 10, 50 and 60 arrays.JSONPath TesterTest JSONPath expressions live: filters, slices, wildcards and recursive search, with matches highlighted.Mermaid Diagram EditorWrite Mermaid code and see flowcharts, sequence, Gantt and ER diagrams live. Export SVG or PNG.Country Codes ListSearch ISO 3166 alpha-2, alpha-3 and numeric country codes with calling codes and TLDs.Git Cheat SheetSearchable Git command reference by task, with copy buttons and an undo/rename/fix wizard.HAR File ViewerOpen a .har file to see a waterfall timeline, headers, bodies, timings and size totals.jq PlaygroundRun jq filters on JSON in your browser with live output, flags and an example library.Markdown Cheat SheetInteractive Markdown syntax reference: edit every example and see the live rendered preview.XPath TesterTest XPath expressions on XML or HTML: highlighted matches, node paths, values and examples.EML File ViewerOpen .eml email files to read the message, headers and raw source and save attachments.Graphviz Online ViewerWrite Graphviz DOT code and render graphs live; switch layout engines, export SVG or PNG.JavaScript Online CompilerWrite and run JavaScript in your browser with a console, timing, error lines and share links.Jupyter Notebook ViewerOpen .ipynb files and read code, Markdown, math, tables, plots and errors without Python.LaTeX Table GeneratorEdit a table like a spreadsheet or paste from Excel and get LaTeX tabular or booktabs code.Log File ViewerOpen huge log files with level colors, regex and time filters, JSON pretty-print and tail -f.Logic Gate SimulatorBuild logic circuits with AND, OR, NOT, XOR gates and flip-flops; see live outputs and truth tables.MSG File ViewerOpen Outlook .msg emails in your browser: sender, recipients, body, headers and attachments.Online Code EditorVS Code-style editor in your browser: tabs, 50+ languages, find/replace, autosave.Online Hex EditorOpen any file as hex and ASCII, edit bytes, search, inspect values and save the result.PHP Online CompilerRun PHP 8 code in your browser with output, HTML preview, error lines and share links.PlantUML EditorWrite PlantUML and see sequence, class, activity and more diagrams live. Export SVG or PNG.EditorConfig GeneratorBuild an .editorconfig with indent, charset, line endings and trim rules per file pattern.Folder Compare ToolCompare two folders by file list, size and SHA-256 hash, then open a text diff of changed files.Glob Pattern TesterTest glob patterns like **/*.js, {a,b} and !exclusions against a list of file paths.JMESPath TesterEvaluate JMESPath expressions against JSON live, the query language used by the AWS CLI.MongoDB Query TesterTest MongoDB find filters, projections and aggregation pipelines on sample JSON documents.Semantic Version CalculatorBump, compare, sort and test SemVer versions against npm ^, ~ and x ranges.XSLT TesterRun an XSLT 1.0 stylesheet on XML in your browser and see the output as HTML, XML or text.ASCII Diagram EditorDraw boxes, arrows and text on a character grid and copy plain-text diagrams for code and READMEs.DBF File ViewerOpen dBase .dbf files and shapefile tables, search and sort records, export CSV or XLSX.MBOX File ViewerOpen .mbox mail archives: list and search messages, read them, save attachments, export EML.MDB File ViewerOpen Access .mdb and .accdb databases in your browser: list tables, view rows, export CSV.Shapefile ViewerView zipped shapefiles on a map with the attribute table, then export to GeoJSON or CSV.Sorting Algorithm VisualizerWatch bubble, insertion, merge, quick, heap and radix sort step by step with live counters.Lottie ViewerOpen Lottie JSON or .lottie files to play, pause, scrub frames, change speed and see details.Diff ViewerPaste a git diff or .patch file and view it side by side or inline, with file navigation.
    See all 53 Code Playgrounds & Testers →