Skip to content
RegexCraft
  • 100% client-side isolated
  • 0ms latency

Regex cheat sheet and pattern library

Patterns that are already tested: every entry lists the examples it must match and the ones it must reject, and one click hands it to the tester with a sample ready to run.

  • 28 tested patterns
  • Examples asserted in CI
  • Load into the tester

Start from a pattern, not from a blank box

Each card tells you what the pattern deliberately does not do — the email pattern is not RFC 5322, the credit-card pattern checks format but not the Luhn checksum — so the behaviour you get is the behaviour it documents.

Pattern library · 28 tested patterns

Search by name, by the pattern itself, or by what it does.

28 of 28 patterns

Validation

Accept or reject a whole input.

  • Email address

    validation
    /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/

    Practical validation: one @, a dotted domain and a two-letter-or-longer TLD. It does not attempt RFC 5322, whose grammar allows quoted local parts and comments that no signup form should accept.

    matches: "ada@example.com", "first.last+tag@sub.domain.co", "a_b-c%d@example.museum"rejects: "no-at-sign", "@example.com", "user@domain" +2 more
  • Phone number (E.164)

    validation
    /^\+[1-9]\d{1,14}$/

    The international format: a plus, a non-zero country code, then up to 15 digits in total. This is what an API wants to receive, unlike the display format below.

    matches: "+14155552671", "+442071838750", "+81312345678"rejects: "4155552671", "+0123456", "+1234567890123456" +1 more
  • Phone number (US display)

    validation
    /^\(?([2-9]\d{2})\)?[ .-]?(\d{3})[ .-]?(\d{4})$/

    Accepts the four ways a US number is written, and rejects an area code starting with 0 or 1 because those do not exist. The groups are area code, prefix and line number.

    matches: "(415) 555-2671", "415-555-2671", "415.555.2671", "4155552671"rejects: "(015) 555-2671", "415-555-267", "(415) 555 26711" +1 more
  • Credit card number (format)

    validation
    /^(?:(?:\d{4}[- ]?){3}\d{4}|\d{13,19})$/

    A format check only: grouped in fours or bare, 13 to 19 digits, which covers every major issuer. It does not run the Luhn checksum, so a well-shaped but invalid number still passes — run the checksum separately.

    matches: "4242 4242 4242 4242", "4242424242424242", "371449635398431", "6011-1111-1111-1117"rejects: "4242 4242 4242", "4242424242424a", "1234-5678-9012-345" +1 more
  • Username

    validation
    /^[A-Za-z0-9_]{3,16}$/

    Letters, digits and underscores, three to sixteen characters. No hyphens or dots, which keeps it usable as a path segment and a mention without escaping.

    matches: "ada_lovelace", "user01", "ABC"rejects: "ab", "has-dash", "has space" +1 more
  • US ZIP code

    validation
    /^\d{5}(?:-\d{4})?$/

    Five digits, optionally followed by the four-digit extension. The hyphen group is optional but the digits after it are not, so a trailing hyphen is rejected.

    matches: "94103", "94103-1234"rejects: "9410", "94103-123", "ABCDE" +1 more

Web & network

URLs, addresses, tags and links.

  • URL parser (with groups)

    web
    /^(https?):\/\/([^\/\s:]+)(?::(\d+))?(\/[^\s?#]*)?(?:\?([^#\s]*))?(?:#(\S*))?$/i

    Six capture groups: scheme, host, port, path, query and fragment. Anything after the first # is the fragment, which is what a browser does.

    matches: "https://example.com/path?a=1#top", "http://localhost:3000", "https://api.example.com:8443/v1/users?page=2"rejects: "ftp://example.com", "example.com", "https://" +1 more
  • IPv4 address

    web
    /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/

    Range-checked per octet, so 256 and 999 are rejected. Leading zeros are rejected too, because 010.1.1.1 means different things to different parsers.

    matches: "192.168.1.1", "8.8.8.8", "255.255.255.255", "0.0.0.0", "10.0.0.255"rejects: "256.1.1.1", "192.168.1", "192.168.1.1.1" +2 more
  • IPv6 address

    web
    /^(?:(?:[0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}|(?:[0-9A-Fa-f]{1,4}:){1,7}:|(?:[0-9A-Fa-f]{1,4}:){1,6}:[0-9A-Fa-f]{1,4}|(?:[0-9A-Fa-f]{1,4}:){1,5}(?::[0-9A-Fa-f]{1,4}){1,2}|(?:[0-9A-Fa-f]{1,4}:){1,4}(?::[0-9A-Fa-f]{1,4}){1,3}|(?:[0-9A-Fa-f]{1,4}:){1,3}(?::[0-9A-Fa-f]{1,4}){1,4}|(?:[0-9A-Fa-f]{1,4}:){1,2}(?::[0-9A-Fa-f]{1,4}){1,5}|[0-9A-Fa-f]{1,4}:(?::[0-9A-Fa-f]{1,4}){1,6}|:(?:(?::[0-9A-Fa-f]{1,4}){1,7}|:))$/

    Covers the full eight-group form and every legal use of `::` compression, including the loopback `::1` and the unspecified `::`. It does not validate the IPv4-mapped form such as `::ffff:192.168.1.1`.

    matches: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "::1", "fe80::1", "2001:db8::1", "::"rejects: "1:2:3:4:5:6:7:8:9", "12345::1", "not:an:ipv6" +1 more
  • Hex colour code

    web
    /^#(?:[0-9A-Fa-f]{3}|[0-9A-Fa-f]{4}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/

    All four CSS lengths: #rgb, #rgba, #rrggbb and the eight-digit form with alpha. The leading # is required, which is what stops it matching bare words.

    matches: "#fff", "#A5F3FC", "#0d1117", "#a78bfa80"rejects: "#ff", "#gggggg", "0d1117" +1 more
  • MAC address

    web
    /^([0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}$/

    Six hex pairs separated by colons or hyphens, matching both the IEEE and the Windows spelling. It is not case-sensitive, because MAC addresses are written both ways in the wild.

    matches: "00:1B:44:11:3A:B7", "00-1b-44-11-3a-b7", "aa:bb:cc:dd:ee:ff"rejects: "00:1B:44:11:3A", "00:1B:44:11:3A:B7:C8", "ZZ:1B:44:11:3A:B7" +1 more
  • HTML tag

    web
    /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi

    Matches an opening, closing or self-closing tag and captures the tag name. It deliberately does not parse attributes into groups: use a real parser for anything structural.

    matches: "<div class=\"x\">", "</p>", "<br/>", "<a href='#'>"rejects: "div", "<3>", "<-bad>" +1 more
  • Twitter / X handle

    web
    /^@\w{1,15}$/

    An @ followed by up to fifteen word characters, which is the platform's own limit. Word characters cover letters, digits and the underscore.

    matches: "@regexcraft", "@a", "@user_01"rejects: "regexcraft", "@too_long_handle", "@has space" +1 more
  • Hashtag

    web
    /^#[A-Za-z][A-Za-z0-9_]*$/

    A # followed by a letter, then any mix of letters, digits and underscores. Requiring a leading letter is what stops it matching an anchor or an issue number.

    matches: "#regex", "#regex101", "#a_b"rejects: "#1tag", "tag", "#has space" +1 more

Data formats

Identifiers, dates and encodings.

  • UUID v4

    data
    /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i

    Version-specific: the third group starts with 4 and the fourth with 8, 9, a or b, which are the variant bits. A v1 UUID therefore fails, which is usually what you want when a column claims to hold v4.

    matches: "3f2504e0-4f89-41d3-9a0c-0305e82c3301", "9C858901-8A57-4791-81FE-4C455B099BC9"rejects: "3f2504e0-4f89-11d3-9a0c-0305e82c3301", "3f2504e04f8941d39a0c0305e82c3301", "not-a-uuid"
  • ISO 8601 date

    data
    /^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/

    Calendar shape only: a four-digit year, a 01-12 month and a 01-31 day. It rejects 2024-13-01 and 2024-00-10 but still accepts 2024-02-31, because a regex cannot know about leap years.

    matches: "2024-01-31", "1999-12-01", "2024-06-15"rejects: "2024-13-01", "2024-00-10", "24-01-01" +2 more
  • Semantic version

    data
    /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/

    The full semver 2.0 grammar for the numeric core plus the optional pre-release and build metadata. Leading zeros are rejected, and so is a leading v, because those are not part of the version.

    matches: "1.0.0", "2.13.7-beta.1", "0.1.0+build.5", "10.20.30-rc.1"rejects: "1.0", "01.0.0", "v1.0.0" +2 more
  • Base64 blob

    data
    /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/

    Standard alphabet with correct padding, so a truncated string is rejected. An empty string passes, which is correct: it is a valid encoding of zero bytes.

    matches: "SGVsbG8=", "aGVsbG8gd29ybGQ=", ""rejects: "SGVsbG8", "not base64!", "SGVsbG8==="
  • Signed integer or decimal

    data
    /^-?\d+(?:\.\d+)?$/

    An optional sign, digits, and an optional fractional part. Scientific notation and thousands separators are deliberately excluded, because both hide a locale decision.

    matches: "42", "-3.14", "0", "-0.5"rejects: "1.2.3", "1e5", "1,000" +1 more
  • JSON string literal

    data
    /^"(?:[^"\\]|\\.)*"$/

    Double quotes with correctly escaped inner quotes and backslashes. It is the piece of a JSON grammar worth having to hand when you are scanning logs for a serialised payload.

    matches: "\"hello\"", "\"with \\\"escape\\\"\"", "\"\""rejects: "\"unterminated", "no quotes", "\"trailing\\\\\""

Text processing

Clean up or reshape prose.

  • URL slug

    text
    /^[a-z0-9]+(?:-[a-z0-9]+)*$/

    Lowercase words joined by single hyphens. Because every hyphen is followed by at least one character, it rejects the three slug mistakes that break a canonical URL: leading, trailing and doubled hyphens.

    matches: "my-first-post", "post-2024", "abc", "a1-b2-c3"rejects: "My-First-Post", "my--post", "-leading" +2 more
  • Markdown link

    text
    /^\[([^\]]+)\]\(([^)\s]+)(?:\s+"([^"]*)")?\)$/

    Splits the label, the URL and the optional title into three groups. The URL group refuses whitespace, which is why the title has to be quoted, exactly as the Markdown spec requires.

    matches: "[Docs](https://example.com)", "[Docs](https://example.com \"The docs\")"rejects: "[Docs]", "(https://example.com)", "[Docs]( )" +1 more
  • Collapse repeated whitespace

    text
    /[ \t]{2,}/g

    Not anchored, so it finds every run of two or more spaces or tabs. Pair it with a single space as the replacement and a paragraph reflows without losing its line breaks.

    matches: "a b", "a\t\tb"rejects: "a b", "one space per word"
  • Duplicated word

    text
    /\b(\w+)\s+\1\b/gi

    The classic backreference: group 1 captures a word and `\1` demands the same word again. The word boundaries stop it firing inside a single longer word.

    matches: "the the cat", "word WORD", "one one"rejects: "the cat", "one two", "together"
  • Trailing whitespace

    text
    /[ \t]+$/gm

    With the m flag, $ also matches before every line break, so this strips the invisible trailing spaces that show up as noise in code review diffs.

    matches: "line one ", "tab at end\t"rejects: "clean line", " leading is fine"

Security

Scan for secrets and weak input.

  • Strong password policy

    security
    /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{12,}$/

    Four lookaheads assert a lower-case letter, an upper-case letter, a digit and a symbol somewhere ahead, then the body requires twelve characters. Lookaheads consume nothing, which is what lets all four apply to the same text.

    matches: "Str0ng!Passw0rd", "aB3$aB3$aB3$", "P@ssw0rd-With-Length"rejects: "short1!A", "alllowercase1!", "NoSymbols12345" +1 more
  • Suspicious secret key name

    security
    /\b(api[_-]?key|secret|password|token|passwd|credential)s?\b/gi

    Scans configuration keys and diffs for the names that usually carry a credential. It matches the name, not the value, so it stays useful on a file whose secrets have already been rotated.

    matches: "api_key", "SECRET", "password", "my_token", "credentials"rejects: "keyboard", "tokenizer", "secretive" +1 more
  • SQL string concatenation

    security
    /(?:"|')\s*\+\s*\w+|\bexec\s*\(|\bOR\b\s+1\s*=\s*1/gi

    Looks for the three shapes that usually mean a query is being built by hand: a quoted fragment added to a variable, a dynamic EXEC, and the classic tautology. It is an audit hint, not a proof.

    matches: "\" + userInput", "EXEC (", "OR 1=1", "or 1 = 1"rejects: "SELECT * FROM users WHERE id = ?", "prepare and bind", "ORDER BY name"
  • 100% client-side isolated
  • 28 verified patterns
  • every example asserted in CI

How it works

Regex tooling that runs in your tab

No proxy, no sign-up and nothing to wait for: patterns are compiled by your browser, matches are drawn inside this page and snippets are generated while you type.

  1. 1. Write the pattern, watch the matches

    The studio re-runs your browser's engine on every keystroke: matches highlight in place, the capture table fills in, and a syntax error points at the exact line and character.

  2. 2. Read the capture table

    Groups, positions and names are listed per match, and a group that did not participate is drawn differently from one that matched zero characters — the detail behind most "why did this match" questions.

  3. 3. Take the code with you

    One pattern becomes runnable JavaScript, TypeScript, Python, PHP, Java, Go or C#. Flags, string quoting and replacement syntax are translated per language, and anything a target cannot express is listed rather than dropped.

  4. 4. Start from a pattern that is already tested

    Every entry in the library carries the examples it must match and the examples it must reject. The same cases run against the real engine, so "tested" is a claim the build enforces.

Privacy by architecture

Nothing is uploaded — and you can verify it

Privacy claims are cheap, so this one is falsifiable: there is no server-side code path here that could receive your data even if it wanted to.

  • No server, so nothing to log

    RegexCraft ships no backend route that accepts a pattern, a test string or a replacement. Open DevTools, watch the Network tab and use any tool: the only requests are the page assets.

  • Your pattern stays in the tab

    Patterns, test strings and matches live in React state inside this tab. They are never written to localStorage. The only thing that travels between pages is the optional hash of a "load into tester" link, and a hash is never sent in a request.

  • Deterministic verdicts

    The same pattern, flags and test string always produce the same matches, groups and positions. Only the duration varies with your machine, which is why it is labelled as a relative measure rather than a benchmark.

Free forever, no account required — the tools are static pages that run entirely on the client.

Regex cheat sheet FAQ

What the patterns promise, what they deliberately skip, and how the examples are verified.

Are these patterns safe to paste into production?

Treat them as a vetted starting point, not as a specification. Each one documents what it deliberately does not do: the email pattern is not RFC 5322, the credit-card pattern checks format but not the Luhn checksum, and the date pattern cannot know about leap years.

Why does the reference mention engine differences?

Because the flavours disagree in ways that break real code. `\b` and lookbehind behave differently in RE2 and in .NET, and `\d` matches non-ASCII digits in some engines only. Where it matters, the notes say which engine the example assumes.

What does 'Load into tester' do?

It opens the tester with the pattern, its flags and a ready-made test string already filled in, passed through the URL fragment. Nothing touches a server: a fragment is never sent in a request, so the pattern stays in the browser.

Do you validate the patterns automatically?

Yes. Every entry carries examples that must match and examples that must not, and the build runs all of them through the real engine. A pattern that starts accepting something it documents as invalid breaks the build.

Is the syntax reference just a copy of the MDN page?

No, it is written for the questions that actually come up: which tokens consume a character and which only assert a position, why `^` and `$` surprise people, and the four engine differences that break a port most often.

  • Regex Tester

    Paste a pattern and your own text: every match is highlighted as you type, with the capture table, named groups, positions and execution time. Syntax errors are reported at the exact character, and dangerous backtracking is flagged before you run it.

    Open tool
  • Code Generator

    Turn a pattern into production code for JavaScript, TypeScript, Python, PHP, Java, Go and C#. Choose match, replace or extract-all, and see the flags, the string quoting and the replacement syntax translated per language.

    Open tool
  • Explainer

    Soon

    An animated walk through the engine: each alternation branch, quantifier expansion and backtracking step drawn as a tree, so a pattern that behaves unexpectedly can be read rather than guessed at. In development on the same client-side engine.

    In development