Toolvito

Works on this device. File exports run online.

Regex Tester & Builder

Type a pattern and some text: matches are highlighted as you type, with their groups and positions, and every part of the pattern is explained. Build a pattern from examples or pick a common one, copy it for your language, or run it in real Python or Java to see what they find.

Test a regular expression

Flags

										

What the pattern means

    Build a pattern

    
    								

    Other languages

      
      								

      Run in Python or Java

      Run in Python or Java

      Runs the pattern of the tester above in a real engine of another language on the Toolvito server, with a time limit.

      More options
      More flags

      The flags i, m and s ticked above are used too. ASCII is for Python only; the two Unicode flags are for Java only.

      1 to 5,000.

      100 to 5,000 milliseconds. The run is stopped after this time.

      The browser tester processes the pattern and text on this device. Choosing Run under Run in Python or Java sends the pattern, flags, text and replacement to Toolvito. Download the result within one hour after the job finishes. Choose Delete files now to request earlier removal. The hourly cleanup normally removes files within one to two hours after completion.

      How to test a regex

      1. Type the pattern without slashes, and tick the flags (g all matches, i ignore case, m lines, s dot matches line breaks, u Unicode).
      2. Paste the text to search. Matches are marked and listed with their groups.
      3. Tick Replace to see the text after replacing ($1 or $<name> insert groups).

      One pattern, several languages

      • The tester uses JavaScript’s engine. Most patterns mean the same in Python, Java, PHP (PCRE), C# and Go; the differences that matter (named groups, look-behind, back-references, \d with Unicode, $ before a final line break) are listed for your pattern.
      • The code box writes the pattern for each language, with its flags and the named-group syntax converted for Python.
      • Go’s RE2 engine has no look-around or back-references: patterns that use them do not work there.

      Run it in Python or Java

      • Under Run in Python or Java, choose Python’s re, the Python regex package or Java’s java.util.regex, and what to do: find all matches, check the whole text, replace or split. Select Run.
      • The pattern, flags (i, m, s), text and replacement of the tester are used. Syntax that only JavaScript has is written the engine’s way first: named groups become (?P<name>…) for Python’s re, and a replacement $1 or $<name> becomes \1 or \g<name> for Python and $1 or ${name} for Java. The result says exactly what was run.
      • Python counts positions in characters. Java counts UTF-16 code units, as its own Matcher does, so an emoji counts as two. Line and column always count characters.
      • The results can be downloaded as a CSV table of the matches, the replaced text and a JSON file with every group.

      Time limit

      • Some patterns backtrack so much that they would run for hours on a short text (catastrophic backtracking, for example (a+)+$ or (.*?,){11}P). This is also how a regex can be used to slow a server down (ReDoS).
      • The tester in your browser stops after 2 seconds. On the server each run stops after the time limit you choose (0.1 to 5 seconds, 1 second if you do not choose) and the page says that the pattern was stopped. The engine runs in a separate process that is ended at the limit.
      • Java 9 and later remember some failed repeats and answer (a+)+$ at once, while Python backtracks; patterns like (.*?,){11}P are slow in both. Fix such patterns with exclusive repeats ([^,]*, instead of .*?,) or atomic groups and possessive repeats where the engine has them.

      Building a pattern

      Type a few examples, one per line: when they share a shape (digits, letters and the same punctuation in the same places), the pattern uses classes and lengths; otherwise it lists the examples. Check it against counter-examples. The common patterns state their limits; an e-mail pattern can only check the form of an address.

      Related tools