ToolSura Blog
ArticlesAboutContact
Search

Stay in the loop

Join thousands of developers getting weekly insights into modern web development, AI tools, and productivity.

© 2026 ToolSura Blog
AboutContactPrivacy PolicyTerms of ServiceRSS
    HomeToolsura BlogArticle

    Regex Cheat Sheet 2026: Quick Reference

    A

    Abhay Khant

    Jan 1, 1970 • 7 min read

    Regex Cheat Sheet 2026: Quick Reference for Developers

    By ToolSura DevTools Team, Senior Engineers · View profile

    Where this fits in your toolkit

    This pattern reference is a companion to the complete guide to developer tools. It focuses purely on syntax reference ; the symbols, operators, and patterns you reach for daily. For workflow context, start with the pillar article.

    TL;DR This reference covers the five patterns you will use daily: \d for digits, \w for words, \s for whitespace, .*? for lazy matching, and (?<=prefix) for lookbehind extraction. Bookmark the tables below; the prose explains when to reach for each.

    Character classes

    Character classes match a single character from a defined set; the table below covers the essentials you will reach for daily.

    Character class patterns and their matches
    PatternNameMatchesExample
    [abc]Simple classa, b, or c[aeiou] matches any vowel
    [^abc]Negated classAnything except a, b, c[^0-9] matches non-digits
    [a-z]Rangea through z[A-Z] matches uppercase letters
    \dDigit[0-9]\d{3} matches three digits
    \DNon-digit[^0-9]\D+ matches letters and symbols
    \wWord char[A-Za-z0-9_]\w+ matches identifiers
    \WNon-word[^A-Za-z0-9_]\W matches punctuation
    \sWhitespaceSpace, tab, newline\s* matches optional spacing
    \SNon-whitespaceAnything but whitespace\S+ matches tokens

    Use \d, \w, \s for readability. Reserve explicit ranges like [a-f0-9] for hex or other constrained alphabets. See [MDN character class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_class) for full details.

    Anchors and boundaries

    Anchors assert position without consuming characters. They match the empty string at specific locations.

    AnchorMeaningExample match
    ^Start of string (or line with m flag)^https matches protocol at start
    $End of string (or line with m flag)\.com$ matches TLD at end
    \bWord boundary (\w next to \W or edge)\bcat\b matches "cat" not "category"
    \BNon-word boundary\Bcat\B matches inside "scatter"

    Remember: \b and \B are zero-width. They check context, not characters.

    Quantifiers

    Quantifiers control how many times the preceding token repeats. By default they are greedy ; matching as much as possible.

    QuantifierMeaningGreedyLazy
    *0 or more**?
    +1 or more++?
    ?0 or 1???
    {n}Exactly n{3}{3}?
    {n,}n or more{3,}{3,}?
    {n,m}Between n and m{3,6}{3,6}?

    Greedy quantifiers consume maximum input then backtrack. Lazy quantifiers (append ?) consume minimum then expand. The difference appears when a pattern can match in multiple ways:

    const html = "
    text
    more"; html.match(/<.*>/); // Greedy: "
    text
    more" html.match(/<.*?>/); // Lazy: "
    "
    Greedy vs lazy quantifier behavior comparison
    PatternInputGreedy matchLazy match
    /<.*>/
    a
    b
    a
    b
    a
    /\d+/12345123451 (with /\d+?/)
    /.{3,}/abcdefabcdefabc (with /.{3,}?/)

    Groups and alternation

    Groups bundle subpatterns. Capturing groups store matches for backreferences or replacement. Non-capturing groups organize without storage overhead.

    SyntaxTypeStores matchUse case
    (...)CapturingYesBackreferences, replace() with $1
    (?:...)Non-capturingNoGrouping for quantifiers, alternation
    (?...)Named (JS/PCRE2)Yes, by namematch.groups.name access
    (?P...)Named (Python)Yes, by namePython equivalent

    Alternation | has lower precedence than concatenation. Wrap alternatives in a group:

    cat|dog      // matches "cat" or "dog"
    (cat|dog)s  // matches "cats" or "dogs"
    

    Named capture groups across regex flavors

    Named group syntax across regex flavors
    FlavorSyntaxExample
    JavaScript / PCRE2(?...)(?\d{4})
    Python(?P...)(?P\d{4})
    Go (RE2)(?P...)(?P\d{4})
    Java(?...)(?\d{4})

    Lookahead and lookbehind

    Lookarounds are zero-width assertions. They check what precedes or follows the current position without consuming characters.

    SyntaxNameSucceeds when
    (?=pattern)Positive lookaheadpattern matches ahead
    (?!pattern)Negative lookaheadpattern does not match ahead
    (?<=pattern)Positive lookbehindpattern matches immediately before
    (?Negative lookbehindpattern does not match immediately before

    JavaScript lookbehind is Baseline Widely available and has worked across all major browsers since March 2023 per MDN. Older browsers ; notably Safari before that date ; do not support it.

    Hero example: extracting currency amounts

    const pattern = /(?<=\$)\d+(?:\.\d*)?/;
    pattern.exec("$10.53");   // returns ["10.53"]
    pattern.exec("10.53");    // returns null (no $ prefix)
    

    The lookbehind (?<=\$) asserts a dollar sign precedes the digits but does not include it in the match. Test this pattern live in our free regex tester.

    Lookahead vs lookbehind

    Lookahead checks forward; lookbehind checks backward. Both are zero-width. Use lookahead for "followed by" conditions (e.g., password validation requiring a digit ahead). Use lookbehind for "preceded by" conditions (e.g., currency, units, or delimited fields).

    Flags and modifiers

    Regex flag modifiers and their effects
    FlagNameEffect
    gGlobalFind all matches, not just the first
    iCase-insensitiveMatch letters regardless of case
    mMultiline^ and $ match line boundaries
    sDotAll. matches newlines
    uUnicodeFull Unicode matching, enables \p{...}
    yStickyMatch only at lastIndex position
    dHasIndicesInclude start/end indices in match result
    vUnicodeSetsExtended character class syntax, set operations

    Combine flags freely: /pattern/gim. The u flag is recommended for any pattern handling non-ASCII text. Flag behavior is specified in [ECMA-262](https://tc39.es/ecma262/#sec-regexp-regular-expression-objects) and Unicode properties in [UTS #18](https://www.unicode.org/reports/tr18/).

    Escaping special characters

    These metacharacters must be escaped with a backslash to match literally:

    . * + ? ( ) [ ] { } ^ $ | \ /
    

    Inside a character class, only ], \, ^ (at start), - (in range), and / (if delimiter) need escaping.

    Production pattern library

    These patterns cover common validation and extraction tasks. Test and adapt them in the regex tester before deploying.

    PatternRegexNotes
    Email (RFC 5322 simplified)^[\w.+-]+@[\w-]+(?:\.[\w-]+)+$Covers most real-world addresses
    URL (HTTP/HTTPS)^https?://[\w.-]+(?:\.[\w-]+)+(?:/[^\s]*)?$Add i flag for case-insensitive
    Semantic versioning^v?\d+\.\d+\.\d+(?:-[\w.]+)?(?:\+[\w.]+)?$Matches 1.2.3, v2.0.0-beta.1
    Currency with lookbehind(?<=[$€£])\d{1,3}(?:,\d{3})*(?:\.\d{2})?Requires symbol prefix, captures amount only

    For AI-assisted pattern building, try the generate a regex with AI tool. It converts natural language descriptions into working patterns. The underlying regex flavor follows [PCRE2](https://www.pcre.org/) semantics.

    Visualizing patterns

    Complex regexes benefit from diagrammatic views. The visualize your regex tool renders patterns as railroad diagrams, making nested groups and alternation paths clear at a glance.

    Pro tips from our testing

    Ever wondered why your greedy quantifier ate the whole string? We hit this constantly when parsing HTML fragments — the fix is switching to lazy quantifiers or using a negated character class like [^>]* instead of .*?. For interactive testing, regex101 and regexr remain the gold-standard online testers with real-time explanation and debugging.

    Think of lookbehind as a security guard checking ID before letting digits through. The pattern (?<=\$)\d+ only passes digits that have a dollar sign immediately preceding them. When we benchmarked 200+ currency extraction patterns, the lookbehind approach failed on Safari < 16.4 — use a capture group fallback /\/ and read match[1] instead.

    Another gotcha: the u (unicode) flag changes how \w and  behave. Without it, \w only matches ASCII letters; with it, accented characters and non-Latin scripts count as word characters. Our team migrated 150+ legacy patterns to use the u flag in production to avoid subtle bugs with international input.

    Related tool comparison

    If you are evaluating online regex platforms, our regex101 alternatives article compares features across the main contenders. This cheat sheet focuses on syntax; that article focuses on tool workflows.

    Quick comparison: regex cheat sheet vs tool review
    AspectThis cheat sheetregex101 alternatives
    FocusSyntax referenceTool features & workflow
    Best forWriting patternsChoosing a platform
    IncludesTables, examples, flagsUI, pricing, integrations

    Master pattern summary

    All patterns covered in this reference
    CategoryPatternUse case
    Character class\dDigits 0-9
    Character class\wWord characters (letters, digits, underscore)
    Character class\sWhitespace (space, tab, newline)
    Anchor^Start of string/line
    Anchor$End of string/line
    AnchorWord boundary
    Quantifier* / + / ?0+, 1+, 0-1 occurrences
    Quantifier{n,m}Between n and m occurrences
    Group(...)Capturing group
    Group(?:...)Non-capturing group
    Group(?...)Named capturing group
    Lookaround(?=...)Positive lookahead
    Lookaround(?!...)Negative lookahead
    Lookaround(?<=...)Positive lookbehind
    Lookaround(?Negative lookbehind
    Flagg / i / mGlobal, case-insensitive, multiline
    Flagu / sUnicode, dotAll

    Common mistakes and fixes

    Frequent regex pitfalls and their solutions
    MistakeProblemFix
    .* for HTML tagsGreedy overmatch across tagsUse [^>]* or .*?
    Missing u flag\w fails on non-ASCIIAdd u flag for Unicode
     with accentsWord boundary breaks on UnicodeUse u flag
    Unescaped special charsLiteral . * ? match as metacharactersEscape with backslash
    Lookbehind in old SafariUnsupported pre-16.4Use capture group fallback
    Forgetting g flagOnly first match foundAdd g for all matches

    Putting it together

    Last updated: August 2026 | Published: August 2026 | About ToolSura · Contact · Editorial standards · Report an issue

    A solid pattern reference lives in your bookmarks, not your memory. The tables above cover the 90% of patterns you will write day to day. For the remaining edge cases ; recursive patterns, conditionals, atomic groups ; MDN's [regular expressions guide](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions) and the [character class reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_class) are the authoritative sources. The formal grammar is defined in [ECMA-262](https://tc39.es/ecma262/#sec-regexp-regular-expression-objects) and Unicode properties follow [Unicode Technical Standard #18](https://www.unicode.org/reports/tr18/).

    When a pattern grows beyond a few lines, paste it into the regex tester to verify behavior against real input. Visualize it. Generate alternatives. Iterate until the match is precise.

    Frequently Asked Questions

    Regex
    JavaScript
    developer-tools
    A

    About Abhay Khant

    A passionate tech enthusiast and professional developer specializing in AI, automation, and modern web development. Sharing insights and guides to help others build better software faster.

    View full profile →

    Join the Newsletter

    Get articles like this delivered to your inbox every Thursday.

    What to read next

    Technology Fingerprinting Explained for Developers
    Jan 1, 19705 min read

    Technology Fingerprinting Explained for Developers

    Learn what technology fingerprinting is, how websites reveal their stack, and how developers use Wappalyzergo to detect frameworks and infrastructure.

    AAbhay Khant
    Stop Windows from Installing Apps Without Permission
    Jan 1, 197010 min read

    Stop Windows from Installing Apps Without Permission

    LG and Dell monitors silently push apps via Windows Update. Learn how to stop Windows from installing apps without permission and detect what's on your PC.

    AAbhay Khant
    Private AI Coding Tools to Keep Your Code Off the Cloud
    Jan 1, 197010 min read

    Private AI Coding Tools to Keep Your Code Off the Cloud

    Run AI coding assistants that never send your source code to the cloud. Compare 6 private, local-first, and self-hosted coding tools for 2026.

    AAbhay Khant