Regex Tester


        

    About this tool

    The Regex Tester runs a regular expression live against your own text. It highlights all matches, shows the position and content of every group and calculates the result of a replacement. Each part of the pattern is also explained in plain language. The tool is free and runs entirely in your browser; your test text is not sent anywhere.

    What you can use it for

    Frequently asked questions

    What is a regular expression?

    A regular expression (regex) is a search pattern made of characters and special symbols that describes what a text should look like. It is used to search, validate and transform text, for example to find number sequences or email addresses.

    Is my test text sent anywhere?

    No. Everything runs in your browser and nothing is transmitted. The normal share link contains only the pattern, flags and replacement text. The test text is included only if you explicitly choose that.

    What do the flags g, i, m and s mean?

    g finds all matches instead of only the first, i ignores upper and lower case. m makes ^ and $ match at every line start and end, s lets the dot match line breaks as well. Less common flags such as u, v, y and d are available too.

    Why is only the first match replaced?

    Without flag g, JavaScript replaces only the first match. Turn on g to replace all matches.

    Why does the tool stop on some patterns?

    Patterns with nested repetitions such as (a+)+$ can take exponentially long on unlucky text (catastrophic backtracking). The tool therefore runs patterns in a Web Worker and stops it after 500 ms so the page stays usable. It helps not to nest repetitions and to make alternatives unambiguous.

    Do patterns from PHP or Python work the same way here?

    Not always. The tool uses the JavaScript regex engine of your browser. PHP (PCRE) and Python differ, for instance with atomic groups, possessive quantifiers or inline flags. The code output translates the essentials and flags differences as notes.

    What is the difference between greedy and lazy?

    Greedy quantifiers take as much text as possible: <.+> on <a><b> matches everything. With a trailing ? they take as little as possible, so <.+?> matches <a> and <b> separately.

    Can I reliably validate emails or URLs with this tool?

    Only roughly. The example patterns are deliberately simple and their notes state their limits. Real addresses are more complex; a confirmation email is the reliable check, and for URLs the system's URL parser.

    Background

    Regular expressions originate in theoretical computer science and are now available in almost every programming language, in text editors and in command-line tools. A pattern describes a set of strings: literals stand for themselves, character classes such as \d (digit) or [a-z] stand for one character from a set, and quantifiers such as *, + or {2,5} define how often something occurs. Anchors such as ^, $ and \b describe positions rather than characters.

    Parentheses create groups. They bundle parts so that a quantifier applies to several characters, and they remember the matched text as group 1, 2 and so on. Named groups of the form (?<name>…) are easier to read. In the replacement text, $1 or $<name> access these contents, and $& stands for the whole match. A vertical bar separates alternatives.

    Lookaheads and lookbehinds check what comes before or after a position without consuming it. For example, (?<=€)\d+ finds a number after a euro sign without including the sign in the match. Quantifiers are greedy by default and take as much as possible; with a trailing question mark they become lazy.

    Flags change the search. g returns all matches, i ignores case, m and s control line anchors and the dot. Flag u enables Unicode mode; only then do properties such as \p{L} work, and characters beyond U+FFFF such as emoji count as one character. Without u, \w means only a–z, A–Z, 0–9 and underscore; accented letters are not included.

    Syntax differs between engines. JavaScript has no atomic groups, possessive quantifiers or recursion, PHP uses PCRE, and Python uses the re module. A pattern from one language therefore cannot always be copied unchanged into another.

    A well-known pitfall is catastrophic backtracking: with nested repetitions such as (a+)+$, the engine tries exponentially many ways to split the text when a match fails. This tool therefore runs in a Web Worker with a time limit. Regular expressions are also not suited to everything: nested formats such as HTML cannot be read reliably with them, and a parser is the better choice.

    Help & info

    Protection against endless patterns

    Some patterns take exponentially long on unlucky text (“catastrophic backtracking”, e.g. (a+)+$ on aaaa…b). This tool therefore runs the pattern in a Web Worker and stops it after 500 ms; the page stays usable. 5 s can be allowed on request. In the pattern: do not nest repetitions, make alternatives unambiguous, limit parts.

    Flags at a glance

    Groups, names, replacing

    (…) remembers the match as group 1, 2, … in the order of the opening parentheses; (?<name>…) also gives it a name; (?:…) only groups. In the replacement: $1, $<name>, $& (whole match), $` and $' (before/after), $$ (a dollar sign). If the group does not exist the expression stays literal; if it merely did not participate it becomes empty.

    Lookahead and lookbehind

    (?=…) and (?!…) look ahead, (?<=…) and (?<!…) look back — they only check and consume no characters. In JavaScript the lookbehind may have any length (not in PCRE and Python). Example: (?<=€)\d+ finds the number after the euro sign without taking the sign along.

    Greedy and lazy

    Quantifiers take as much as possible (greedy): <.+> on <a><b> matches everything. With a trailing ? as little as possible (lazy): <.+?> matches <a> and <b> separately. Possessive quantifiers and atomic groups do not exist in JavaScript.

    g, y and lastIndex

    With g or y a RegExp object remembers in lastIndex where the next search starts: repeated test() or exec() therefore gives changing results. This tool resets lastIndex for every run; in your own code prefer matchAll() or replace(). Empty matches (e.g. with a*) advance the search by one character.

    JavaScript is not PCRE

    Patterns from PHP, Perl or Python do not always work in JavaScript: no atomic groups (?>…), possessive quantifiers a++, recursion, \A \z \Z, inline flags (?i) at the start (only (?i:…) in newer browsers). Named groups are (?<n>…), not (?P<n>…). The code snippets translate the essentials and flag the rest as notes.

    Limits of this tool

    Examples and cheat sheet are deliberately rough. Matching uses your browser’s regex engine — behaviour and supported syntax (e.g. v flag, (?i:…)) depend on its version. At most 200 matches are listed, 3000 highlighted, counting stops at 200,000; texts up to 1 million characters. The explainer reads JavaScript syntax, not PCRE or Python.

    Privacy

    Everything runs in your browser, nothing is sent. The normal link contains only pattern, flags and replacement — the test text only if you tick “Include test text” (up to 3000 characters, readably encoded in the link).

    Usage: hovering (or focusing) a row of the explanation lights up its spot in the pattern — and vice versa. Clicking a row selects that spot in the pattern field. In the explanation ↑ ↓ Home End move between rows. Clicking a match in the list highlights it in the text.

    ⚠️ Bitte beachten

    Die Werkzeuge auf dieser Website werden als kostenloses Hobbyangebot bereitgestellt und dienen ausschließlich zur Information und privaten Nutzung. Für die Richtigkeit, Vollständigkeit oder Eignung der Ergebnisse für einen bestimmten Zweck wird keine Gewähr übernommen. Vor Verwendung der Ergebnisse — insbesondere bei finanziellen, rechtlichen oder sicherheitsrelevanten Entscheidungen — sind diese eigenverantwortlich zu prüfen. Eine Haftung für Schäden aus der Nutzung ist ausgeschlossen, soweit dies gesetzlich zulässig ist.