Skip to main content

    Regex Tester

    Test and debug regular expressions in real time. See matches highlighted instantly.

    Free to use. Runs in your browser.

    Enter a regular expression and test string to see matches, capture groups, and replacements in real time. Uses JavaScript regular expressions and common flags (g, i, m, s, u, d).

    Use it to check JavaScript regex behaviour before adding a pattern to app code, logs, or validation rules.

    amp;'()*+,;=-]*">

    Highlighted Matches (2)

    Visit https://iforgeapps.com/tools/ or https://example.com/docs for more info.

    Match Details

    #MatchIndex
    1https://iforgeapps.com/tools/6
    2https://example.com/docs39

    Regular Expressions for Text Matching

    Regular expressions (regex) are patterns that match text. The syntax can look like line noise at first, but once you learn the building blocks, you can validate simple formats, extract data, search and replace across files, and parse logs.

    This tester uses JavaScript's built-in RegExp engine, which supports lookahead, lookbehind, named groups, and Unicode properties. Type your pattern, paste your test string, and see matches highlighted in real time, no server required.

    Regex is best for matching regular text patterns. It is not a substitute for a full parser when the input has nested structure, business rules, or security consequences.

    Essential Regex Syntax

    PatternMeaningExample Match
    .Any character (except newline)a.c matches "abc", "a1c"
    \dAny digit (0-9)\d3 matches "123"
    \wWord character (letter, digit, _)\w+ matches "hello_123"
    \sWhitespace (space, tab, newline)\s+ matches " "
    ^Start of string/line^Hello matches "Hello world"
    $End of string/lineworld$ matches "hello world"
    *Zero or more of previousab*c matches "ac", "abc", "abbc"
    +One or more of previousab+c matches "abc", "abbc" (not "ac")
    ?Zero or one of previouscolou?r matches "color", "colour"
    {n,m}Between n and m repetitions\d{2,4} matches "12", "123", "1234"
    [abc]Character class (any of a, b, c)[aeiou] matches any vowel
    (group)Capture group(\d+)-(\d+) captures "12" and "34"

    Common Ready-to-Use Patterns

    What to MatchPatternNotes
    Email address[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}Covers 99% of real emails
    UK phone number(?:\+44|0)\d{10}Matches 07xxx and +447xxx
    UK postcode[A-Z]{1,2}\d[A-Z\d]?\s?\d[A-Z]{2}Case-insensitive with i flag
    URLhttps?://[\w.-]+(?:\.[\w]+)+[\w._~:/?#@!
    amp;'()*+,;=-]*
    HTTP and HTTPS
    Date (YYYY-MM-DD)\d{4}-\d{2}-\d{2}Doesn't validate actual dates
    Hex colour#[0-9a-fA-F]{3,6}Matches #fff and #ffffff
    IP address (v4)\b(?:\d{1,3}\.){3}\d{1,3}\bDoesn't validate range (0-255)

    Regex Flags Explained

    g, Global

    Find all matches, not just the first one. Essential for search-and-replace operations across entire strings.

    i, Case-insensitive

    Matches regardless of upper/lowercase. "hello" matches "Hello", "HELLO", "hElLo".

    m, Multiline

    Makes ^ and $ match start/end of each line, not just the entire string. Essential for line-by-line processing.

    s, DotAll

    Makes . match newline characters too. Without this, . matches everything except \n.

    u, Unicode

    Enables full Unicode matching. Required for correctly handling emojis, CJK characters, and \p Unicode properties.

    d, HasIndices

    Returns start/end indices for each capture group. Useful when you need to know the exact position of matches.

    Copy-Paste Regex Patterns

    What to MatchPatternExample Match
    UK postcode^[A-Z]{1,2}\d[A-Z\d]?\s?\d[A-Z]{2}$SW1A 1AA
    UK mobile number^07\d{9}$07911123456
    Email (basic)^[^\s@]+@[^\s@]+\.[^\s@]+$user [at] example dot com
    IPv4 address\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b192.168.1.1
    Date (DD/MM/YYYY)\d{2}/\d{2}/\d{4}15/04/2026
    Hex colour#[0-9A-Fa-f]{6}\b#FF5733

    These patterns work in most regex engines (JavaScript, Python, PHP). For production email validation, don't rely on regex alone, send a confirmation email. Regex can check format, but only delivery confirms the address exists.

    Capture Groups and Replacement

    Parentheses do two things: they group part of a pattern, and they capture the matched text for later use. In JavaScript replacement strings, $1 refers to the first capture, $2 to the second, and so on.

    GoalPatternReplacementResult
    Swap date order(\\d{4})-(\\d{2})-(\\d{2})$3/$2/$12026-04-15 becomes 15/04/2026
    Extract domainhttps?://([^/]+)$1https://example.com/docs gives example.com
    Wrap words\\b(urgent)\\b<strong>$1</strong>Marks matching words for HTML output

    Named groups use syntax such as (?<year>\d{4}). They make larger patterns easier to read, especially when several groups have similar shapes.

    Escaping Rules That Cause Bugs

    Pattern input

    To match a literal dot, type \.. A bare dot means any character.

    JavaScript strings

    In source code strings, backslashes need another layer of escaping. The pattern \d+ is written as "\\d+".

    Character classes

    Some characters lose special meaning inside brackets. A dot in [.] is literal, but a caret at the start negates the class.

    URLs and slashes

    If you use regex literal syntax in code, forward slashes must be escaped. In this tester, type the pattern only, without surrounding slashes.

    Performance and Backtracking

    Most regex patterns are fast on normal text. Slowdowns usually come from nested quantifiers, ambiguous alternatives, and patterns that try many paths before failing.

    Risky PatternWhy It HurtsSafer Direction
    (a+)+$Nested quantifiers can retry exponentiallyUse one clear repetition where possible
    (.*)(.*)Two greedy groups fight over the same textMake boundaries explicit
    (cat|caterpillar)Short alternative can win before longer oneOrder longer alternatives first when needed
    .*errorGreedy scan across a huge stringLimit the character class or line scope

    When Regex Is the Wrong Tool

    HTML and XML parsing

    Use a DOM parser for nested tags, attributes, comments, and malformed markup. Regex can help find simple snippets, but it is brittle for full documents.

    JSON and code

    Use JSON.parse, an AST parser, or a language-aware tool. Strings, escapes, and nested blocks quickly outgrow regular matching.

    Security decisions

    Regex can check a rough format, but it should not be the only control for authentication, authorisation, or abuse prevention.

    Related Tools

    How to use this tool

    1

    Enter a regex pattern

    2

    Add flags (g, i, m, etc.)

    3

    Paste your test string

    Common uses

    • Validating email addresses and phone numbers
    • Extracting data from log files and text
    • Find-and-replace with pattern matching
    • Parsing URLs and query parameters
    • Testing patterns before using them in code

    Share this tool

    Frequently Asked Questions

    What regex engine does this tool use?
    JavaScript's built-in RegExp engine, which supports lookahead, lookbehind (ES2018+), named groups, Unicode properties (\p{}), and all standard quantifiers. It matches what runs in current browsers and Node.js.
    Is my data sent to a server?
    No. Everything runs locally in your browser. Your patterns and test strings never leave your device, the matching happens via JavaScript's RegExp object right on the page.
    What regex flags are available?
    g (global, all matches), i (case-insensitive), m (multiline, ^ and $ match line boundaries), s (dotAll, . matches newlines), u (Unicode, correct emoji/CJK handling), and d (hasIndices, returns match positions). Combine them freely: 'gim'.
    Why does my regex match nothing?
    Common causes: forgetting the global flag (g) so only the first match is found; escaping issues (use \\ for a literal backslash in the pattern input); the pattern is case-sensitive but your text has different casing (add the i flag).
    What's the difference between .* and .*? (greedy vs lazy)?
    .* is greedy, it matches as much as possible. .*? is lazy, it matches as little as possible. For HTML like <b>one</b><b>two</b>, the pattern <b>.*</b> matches everything from first <b> to last </b>, while <b>.*?</b> matches each tag pair separately.
    How do I match a literal dot or bracket?
    Escape special characters with a backslash: \\. for a literal dot, \\[ for a bracket, \\( for a parenthesis. Inside a character class [.] a dot is already literal. The characters that need escaping: . * + ? ^ $ { } [ ] ( ) | \\
    What's a capture group and how do I use it?
    Parentheses () create capture groups that extract parts of a match. In the pattern (\\d{4})-(\\d{2})-(\\d{2}), group 1 captures the year, group 2 the month, group 3 the day. Named groups use (?<year>\\d{4}) syntax for readability.
    Can I use lookahead and lookbehind?
    Yes. Positive lookahead (?=...) matches if followed by the pattern. Negative lookahead (?!...) matches if NOT followed. Positive lookbehind (?<=...) matches if preceded by. Negative lookbehind (?<!...) matches if NOT preceded. These don't consume characters.
    How do I write a regex for email validation?
    A practical pattern: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}. This catches 99% of real emails. Perfect email validation via regex is technically impossible, the full RFC 5322 spec is absurdly complex. For production, validate format then send a confirmation email.
    Why is my regex slow on long strings?
    Catastrophic backtracking. Patterns like (a+)+ or (a|a)* cause exponential matching time on non-matching inputs. Fix: use atomic groups (not available in JS), possessive quantifiers, or rewrite to avoid nested quantifiers. The pattern .*.*$ on a long non-matching string is a classic culprit.
    What's the difference between ^ and \\A (start anchors)?
    In JavaScript, ^ matches the start of the string (or each line with the m flag). JS doesn't support \\A. In other languages (Python, Ruby, Java), \\A always matches the absolute start of the string regardless of multiline mode, while ^ changes behaviour with multiline.
    Can regex match across multiple lines?
    By default, . doesn't match newlines and ^ $ only match string boundaries. Add the s flag to make . match newlines. Add the m flag to make ^ $ match line boundaries. Use both 'ms' flags to match patterns that span multiple lines with line-aware anchors.

    Results are for general informational purposes only and should be checked before use. They are not professional advice. See our Disclaimer and Terms of Service.