Free tool

Regex Tester With Live Matches, Replace and a Plain English Explanation

Type a pattern and your test text, and every match lights up with its position and each capture group. The tool also explains the pattern piece by piece and previews a replacement. It uses the JavaScript engine in your browser.

JavaScript (ECMAScript) flavour, run by this browser's engine.

Test text

Matches

    Replace

    
            

    What the pattern says

      Cheat sheet

      Click to put it into the pattern at the cursor.

      Start from

      Use it in code

      Keys

      • / Edit the pattern
      • Enter Next match
      • Shift Enter Previous match
      • Cmd S Download matches

      Matching runs in your browser and nothing is sent anywhere. Your pattern, flags and replacement are remembered on this device, but the test text is not.

      Getting from a pattern to a trustworthy answer

      Whether you are cleaning a list of URLs or writing a redirect rule, the cycle is the same: write, test, adjust. Put the pattern between the slashes, set the flags beside it, and paste real sample text below. Matches are highlighted as you type and the Matches panel lists each one with its position and groups, named groups included.

      Enter moves to the next match and Shift with Enter to the previous one. The slash key jumps back to the pattern box.

      The flags, one by one

      FlagEffect
      gFind every match, not just the first
      iIgnore upper and lower case
      mLet ^ and $ match at each line
      sLet the dot match a line break
      uTreat the text as Unicode characters
      vThe newer Unicode mode with set notation
      yMatch only at the exact position where the last match ended

      Browsers add flags at different times, so a pattern that relies on the newer ones may behave differently on another machine.

      Explain, replace and export

      The What the pattern says panel turns the pattern into sentences, so you can confirm that a character class or a lookahead means what you meant. The cheat sheet below it lists the common pieces, and a click puts one into the pattern at the cursor.

      The Replace box previews a substitution. Use $1 for a numbered group or $<name> for a named one, then copy the result, download it as text, or send it back into the test text. Matches can be copied, or downloaded as CSV or JSON.

      The Start from menu offers ready patterns for email, URL, date, phone, number, hex colour, IPv4, double spaces, a repeated word and an HTML tag. Treat them as starting points and test them on your own data. The Use it in code area writes the pattern out as a line of JavaScript.

      Why a bad pattern does not freeze the page

      Some patterns make the engine backtrack for an enormous time on certain text. Here the matching runs in a background worker and is stopped after 2 seconds, so the page stays usable and you are told the pattern took too long. At most 10,000 matches are listed, and a note appears when there are more.

      That safeguard protects the tool, not your production code. If a pattern is slow here, it can be slow on a server too.

      Three small jobs to try

      Paste a few lines of mixed text and try these in turn.

      • The pattern \b\w+@\w+\.\w+\b with the g flag picks out simple email-like words. Watch what it misses, such as dots in the name part, and adjust.
      • The pattern (\d{4})-(\d{2})-(\d{2}) with the replacement $3/$2/$1 turns a year-month-day date into day, month and year.
      • The pattern \s{2,} with an empty replacement collapses runs of spaces.

      Each of these shows the groups, the replaced text and the explanation, so you can see how one edit to the pattern changes all three at once.

      Slips that cost people time

      • Forgetting to escape the dot. A bare dot matches any character, so write \. for a real full stop.
      • Greedy matching. .* grabs as much as it can. Add a question mark to make it lazy.
      • Testing on one tidy line. Paste messy real data, with blank lines and odd spacing.
      • Assuming other languages behave the same. This is the JavaScript flavour. Other languages differ in lookbehind, named groups and flags.

      When patterns are used to redirect old addresses, they belong in a larger plan. Our redesign SEO checklist covers where redirects fit.

      Frequently asked questions

      Which regex flavour does this use?

      The JavaScript flavour, run by your browser's own engine. A pattern that works here may need small changes in Python, PHP or another language.

      Why does it stop after 2 seconds?

      A pattern with catastrophic backtracking can run for a very long time. The worker is cut off so the page never hangs.

      How do I use a capture group in the replacement?

      Write $1, $2 and so on for numbered groups, or $<name> for a named group, in the Replace with box.

      Can I share a pattern with a colleague?

      Yes. Copy link makes an address that carries the pattern, flags, replacement and test text, so do not use it with private text.

      Is my test text saved?

      No. Only the pattern, the flags and the replacement are remembered on your device.

      Can I get the matches into a spreadsheet?

      Yes. Download the matches as CSV, or as JSON for code.

      More free tools

      • URL encoder and decoder: Percent-encode or decode a URL or a query value, with options for strict encoding and plus signs.
      • Diff checker: Compare two texts or files side by side, merge changes and export a diff.
      • Robots.txt generator: Build or load a robots.txt, add bot rules and test any path against it.
      • Case converter: Convert text to sentence, title, upper, lower or code case, with Chicago and APA title rules.
      • JSON formatter: Format, minify, validate and repair JSON, browse it as a tree, or convert it to YAML or CSV.