Regex tester

    Paste or type sample text below, then highlight any part of it to build a matching pattern automatically β€” no need to write the regex by hand. Live match highlighting, replace mode, and a plain-English breakdown of every pattern you write.

    Presets
    Both inputs are locked β€” unlock at least one to load a preset.
    Sample text Unlocked β€” presets will replace this
    Regular expression Unlocked β€” presets will replace this
    g β€” Global
    Find all matches,
    not just the first
    i β€” Case-insensitive
    A matches a, B matches b
    m β€” Multiline
    ^ and $ match each line
    s β€” DotAll
    . matches newlines too
    u β€” Unicode
    Full Unicode support
    Matches will highlight here as you type…
    What your pattern means
    Advertisement
    Quick reference
    .Any character except newline
    \dAny digit (0–9)
    \wWord character (a–z, 0–9, _)
    \sAny whitespace
    \bWord boundary
    ^Start of string / line
    $End of string / line
    [abc]Any one of: a, b, c
    [^abc]Anything except a, b, c
    [a–z]Any character in range
    +One or more
    *Zero or more
    ?Zero or one (optional)
    {3}Exactly 3 times
    {2,5}Between 2 and 5 times
    (abc)Capturing group
    (?:abc)Non-capturing group
    a|bEither a or b
    \D \W \SUppercase = the opposite
    +? *?Lazy β€” as few as possible

    Common regex patterns and what they mean

    For a quick at-a-glance reference while you build your pattern, see the Quick reference table above β€” the sections below explain what each symbol does and why you'd use it.

    Character classes β€” \d, \w, \s

    \d matches any digit (0–9), \w matches any word character (letters, digits, and underscore), and \s matches any whitespace β€” spaces, tabs, and line breaks. These are the building blocks for matching things like phone numbers, usernames, and formatted text. Capitalising any of them β€” \D, \W, \S β€” flips the meaning to "anything except".

    Anchors β€” ^, $, \b

    ^ matches the start of a string (or line, with the m flag) and $ matches the end. \b matches a word boundary without consuming any text. Anchors are useful when you need to match a whole value rather than part of one.

    Quantifiers β€” *, +, ?, {n,m}

    Quantifiers control how many times the preceding item can repeat. * means zero or more, + means one or more, and ? means zero or one. {3} matches exactly three times, and {2,5} matches between two and five times.

    Groups and alternation β€” (abc), (?:abc), a|b

    Parentheses (abc) create a capturing group you can reference in Replace mode using $1. Prefixing with ?: creates a non-capturing group. The pipe | means "or", so a|b matches either a or b.

    Negation and lazy matching β€” [^abc], \D \W \S, *? +?

    A caret inside square brackets means "any character except these". By default quantifiers are greedy β€” adding ? after one makes it lazy, matching as little as possible. This matters when matching content between delimiters.

    Building a pattern by highlighting your sample text

    Highlight any part of the sample text above and two options appear: Use exact text turns your selection into a pattern that matches that exact string, and Guess pattern generalises it β€” a run of digits becomes \d+, a run of letters becomes a character class, and so on β€” so it also matches similar text elsewhere in your data. Useful when you've spotted an example of what you want to match but don't want to write the pattern by hand.

    Example patterns for common tasks

    Regex for validating an email address

    A practical pattern is [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}. This matches one or more letters, digits, or common symbols before the @, a domain, and a top-level domain of at least two letters.

    Regex for matching a URL

    https?:\/\/[^\s/$.?#].[^\s]* matches both http:// and https:// followed by any non-whitespace characters making up the rest of the address.

    Regex for matching an IPv4 address

    \b(?:\d{1,3}\.){3}\d{1,3}\b matches IPv4 addresses like 192.168.1.1 β€” three groups of one to three digits followed by a dot, then a final group.

    How replace mode works

    Switch to Replace mode to substitute every match with new text, optionally reusing captured groups.

    Using $1, $2 and $& in replacements

    Use $1, $2 etc. to reinsert captured groups into the replacement. $& reinserts the entire match. Useful for reformatting β€” for example turning "Surname, Firstname" into "Firstname Surname".

    Differences from Python and sed syntax

    This tool uses JavaScript regex syntax. Python's re module uses \1, \2 for group references rather than $1, $2. The patterns themselves are usually compatible between languages, but replacement string syntax differs.