Regex tester

Test a regular expression and see the matches highlighted, along with what each group captured and the result of a replacement.

Regex and text

Flags

0 characters · 0 lines

Result

Show

Enter a regex and some text, and the matches are highlighted.

Everything runs on this device. What you enter is never sent anywhere.

Uses JavaScript (browser) regular expressions. Some syntax differs slightly from Python, PHP, Java and others.

Found it useful? We'd love a share

Something not working, or an idea to make it better?

How to use

  1. 1. Enter a regex

    Type the pattern you want to find into “Regular expression”. For symbols that are awkward to type, like \d or [ ], tap the symbol buttons below the field to insert them at the cursor. You can also choose a pattern such as an email address or date from “Pick a common pattern”. Tap “Explain” at the top right of the field to list what each part matches.

  2. 2. Enter your text

    Paste or type the text you want to search into “Text to search” below (tap “Sample” to put in sample text). The matches are highlighted in “Result” below right away, along with how many there are.

  3. 3. Switch flags and check the match list

    Turn off “g All” under “Flags” to find only the first match (turn it back on to find all of them). The “Match list” below shows where each match is and what each group ($1, <year> and so on) captured. Tap a row to select that spot in the text above.

  4. 4. Extract just the matches

    Choose “Extract” above “Result” to list only the matched text, one per line. If the regex has groups, you can pick a group such as <year> instead of “Whole match” in the select box. Turn on “Remove duplicates” to keep each value only once. Tap “Copy extracted results” to copy, or “Save as text” to save a file.

  5. 5. Try a replacement and copy it

    Choose “Replace” above “Result” and type something like $<day>/$<month>/$<year> into “Replace with”. The replaced text appears right away. Tap “Copy replaced text” to copy it.

Great for

  • Checking that your regex is right

    Before it goes into your code, see at a glance whether it matches only what you meant, and nothing extra. When it's ready, pick a language such as Python, PHP or Go and copy it in a form you can paste straight into your code.

    Web developers and people learning to code

  • Reading a regex someone else wrote

    Paste a regex from inherited code or an article and press “Explain” to see, in a few words per part, what it matches, like “One digit repeated 4 times”.

    People reading code and people learning to code

  • Pulling patterns out of logs or tables

    Find email addresses, dates, order numbers and more, list them one per line with “Extract”, then copy them or save them as a text file.

    People who crunch data and support staff

  • Collecting just one group, without duplicates

    Extract only the part in ( ), like the domain of an email address or the host name of a URL. Turn on “Remove duplicates” and a list full of repeats shrinks to one of each.

    People who crunch data and web teams

  • Testing a replacement before you run it

    Check the result of a replacement using $1 and friends before you do a bulk replace in your editor or spreadsheet.

    Anyone tidying up text or tables

  • Building form validation

    Write a regex that checks things like zip codes or phone numbers, and test it against all kinds of input as you go.

    People building forms

Good to know

  • It uses JavaScript regular expressions. Syntax found only in Python, PHP, Java or .NET (such as possessive ++ or (?i)) isn't supported.
  • When you copy for another language, differences in syntax are fixed where possible. Anything that can't be fixed (such as lookbehind in Go) gets a short warning, so test it in that language too.
  • A regex that takes too long is stopped after 2 seconds, and you'll be told. If that happens, reduce the nested repeats.
  • The match list shows the first 300 matches, and up to the first 5,000 are highlighted and extracted (all of them are still counted).

About testing regular expressions

A regular expression describes a pattern of characters, like “four digits in a row” or “letters and digits around an @”, with short symbols such as \d{4} or [\w.]+@[\w.]+. They're used for searching, replacing and validating input in many programs and editors, but one small mistake can make them match something you didn't intend.

This tool tests your pattern with the browser's JavaScript regex engine as you type and highlights every match. It also lists what each group (the parts in ( )) and named group ((?<name>…)) captured for every match, so you can check that you're getting the parts you want. Even patterns that never finish, like (a+)+, won't freeze the page: the search runs separately with a time limit.

Flags compared
When it's onCommon uses
g (All)Finds every matchExtracting, replacing all
i (Ignore case)Treats A and a as the same letterSearching for words
m (Per line)^ and $ match the start and end of each lineLine-by-line checks, logs
s (. matches newlines). also matches line breaksText spanning several lines
u (Unicode)Treats emoji as one character and allows \p{…}Text with emoji or non-Latin scripts

FAQ

Answers to common questions about testing regular expressions.

Is my text or regex sent anywhere?

No. Everything is processed in your device's browser, and your text and regex are never sent to a server or stored. It's safe to use with internal logs or text that contains personal information.

Which regex flavor does it use?

JavaScript (the browser's RegExp). Named groups (?<name>…), lookbehind (?<=…) and \p{…} (with the u flag) all work. Some details differ from Python, PHP, Java and others, so check that language's docs before using the pattern there.

Can I use it in Python or PHP code?

Yes. At the top right of the “Regular expression” field, choose JavaScript, Python, PHP, Java, Ruby or Go and press the copy button to copy the regex as code for that language. Syntax differences are fixed, such as (?P<name>…) in Python, \A and \z in Ruby, or (?i) in Go. Anything the language can't express, like lookbehind in Go, gets a short note below the field. The language you choose is remembered for next time.

Can I paste a regex like /abc/gi?

Yes. If you paste /abc/gi into an empty “Regular expression” field, it's split into the pattern and the flags. The other way around, choose “JavaScript” at the top right of the field and press the copy button to copy the current regex as /…/, ready to paste into JavaScript code.

Can I see what a regex means?

Press “Explain” at the top right of the “Regular expression” field. The regex is split into parts, and each one is listed with what it matches, like “One digit repeated 4 times” or “Group named year”. The contents of a group are indented, so you can also check how the parentheses pair up.

Can I get a list of just the matches?

Choose “Extract” to list the matched text one per line. If the regex has groups, you can pick just that part ($1, <name>). Use “Remove duplicates” to keep each value once, then copy the list or save it as a text file. With the g flag off, you get only the first match.

Where can I see what the groups captured?

The “Match list” on the right shows what $1, $2 … (and <name> for named groups) captured for each match. Groups that didn't take part in the match show “(no match)”.

What can I use in a replacement?

Choose “Replace”, and in “Replace with” you can use $1, $2 … (groups), $<name> (named groups), $& (the whole match) and $$ (a literal $). With the g flag on, every match is replaced; with it off, only the first one.

It says “Stopped because it took too long”

Patterns with a repeat inside a repeat, like (a+)+ or (.*)*, can take an explosive amount of work on text that doesn't match (catastrophic backtracking). To keep the page from freezing, the search stops after 2 seconds. Merge the repeats into one, or narrow down what they match, like [^,]* instead of .*.

How do I search without matching case?

Turn on “i Ignore case” under “Flags”. Uppercase and lowercase letters, like A and a or A and a, are then treated as the same (full-width and half-width characters still count as different).

Why don't ^ and $ match on each line?

By default, ^ and $ only match the start and end of the whole text. To match on every line, turn on “m Per line” under “Flags”.

Can I search for Chinese characters or other scripts?

Yes. “Pick a common pattern” includes “Kanji (Chinese characters)”, which uses \p{Script=Han}. That needs the u flag, so u is turned on automatically when you pick it. With u on, \p{L} matches a letter in any script.

Is it free?

Yes, it's free. No sign-up, no install and no ads. Use it as often as you like, with text of any length.

  • Convert full-width and half-width

    Convert letters, numbers and katakana between full-width and half-width in one go.

  • Hiragana ⇔ katakana converter

    Convert between hiragana, katakana and half-width katakana in one go. Kanji, letters and numbers are left as they are.

  • Character Counter for X, Instagram & YouTube

    See how many characters you have left before the limit on X, Instagram, YouTube and more, counted the way each platform does. Also shows characters, lines, words and bytes.

  • JSON formatter

    Pretty-print JSON or minify it to one line. If there's a mistake, it shows you where.

  • URL Encode / Decode

    Encode text and symbols into a URL-safe form (like %C3%A9) or decode it back to the original text.

  • Password generator

    Choose the length and characters to make hard-to-guess passwords on the spot.