Skip to content

Regex tester

Type a JavaScript regular expression and some text. Every match lights up with its groups, and each part of the pattern is explained in plain words.

Regex tester

Matches

    $1 puts back group 1, $<name> a named group, $& the whole match and $$ a dollar sign. Without the g flag only the first match changes.

    Result
    
    

    What the pattern means

    Click a part to select it in the pattern.

      Tests run in your browser's own JavaScript engine, so a pattern works here as it does in your code. Nothing is uploaded. A shared link keeps the test after the # sign, a part of the address that browsers do not send to servers.

      Advertisement
      A magnifying glass over a line of text with two matches marked

      Which regex flavor this tester runs

      A pattern copied from Python or PHP does not always work in JavaScript. This tester runs on the JavaScript engine of your own browser, so a pattern acts here the same way it does in a web page or in Node.js. PHP uses a library called PCRE, and Python has its own re module. Most signs mean the same in all three. The table lists where they differ.

      What you wantJavaScriptPythonPCRE (PHP)
      A named group(?<name>...)(?P<name>...)(?<name>...)
      A group in the replacement$1 $<name>\1 \g<name>$1 \1
      Very start and end of the text^ and $ without the m flag\A \z\A \z
      Does $ match before a last line break?NoYesYes
      Does \w match é or ж?No, also not with the u flagYesOnly in UCP mode
      Flags inside the patternOnly for a part, like (?i:abc), in browsers from 2025 on(?i) at the start, or (?i:abc)(?i) anywhere
      Atomic groups (?>...) and a++NoYes, since Python 3.11Yes
      Lookbehind lengthAny lengthFixed length onlyLimited

      We checked the Python column against the Python re documentation in November 2026.

      Regex cheat sheet

      Letters and digits match themselves. The signs . * + ? ^ $ ( ) [ ] { } | \ / have a meaning, so put a backslash before one to find the sign itself.

      PatternMatchesExample
      .Any character except a line breakc.t finds cat, cut, c7t
      \d \w \sA digit, a word character (A to Z, a to z, 0 to 9, _), white space\d\d finds 42
      \D \W \SAnything except a digit, a word character, white space\S+ finds each word
      [abc] [a-z]One character from the set or the rangegr[ae]y finds gray and grey
      [^abc]One character not in the set[^,]+ finds the text between commas
      ^ $Start and end of the text, or of each line with the m flag^# finds a # at the start
      \bA word edge\bcat\b skips category
      * + ?The part before it zero or more times, one or more times, or optionalcolou?r finds color and colour
      {3} {2,} {2,4}Exactly 3 times, 2 or more times, 2 to 4 times\d{4} finds 2026
      a|ba or bcat|dog
      (...)A group that saves its match as $1, $2(\d+) kg
      (?:...)A group that does not save(?:ab)+ finds ababab
      (?<name>...)A named group(?<year>\d{4})
      \1 \k<name>The same text a group found before(\w)\1 finds the ll in hello
      (?=...) (?!...)Followed by, not followed by\d+(?=%) finds the 15 in 15%
      (?<=...) (?<!...)After, not after(?<=\$)\d+ finds the 40 in $40
      \p{L}A letter in any alphabet (needs the u flag)\p{L}+ finds Москва
      \. \( \\The sign itself: a period, a bracket, a backslash3\.5 finds 3.5

      The MDN guide to regular expressions lists every part of the JavaScript syntax with more examples.

      Greedy and lazy: .* or .*?

      A repeat sign like + or * is greedy. It takes as much text as it can. On <b>bold</b>, the pattern <.+> runs from the first < to the very last >.

      A ? right after the repeat sign makes it lazy, so <.+?> stops at the first >. A set that leaves out the end sign often works better: <[^>]+> also stops at the first > and never has to step back.

      Advertisement

      Flags

      Flags change how the whole pattern works. In code they go after the last slash, like /cat/gi.

      FlagNameWhat it does
      gglobalFinds every match, not only the first. Without it, replace changes only the first match.
      iignore caseA and a count as the same letter.
      mmultiline^ and $ match at the start and end of every line, not only of the whole text.
      sdot allThe dot matches line breaks too.
      uunicodeAn emoji counts as one character, \p{...} works, and mistakes like \e become errors.
      vunicode setsEverything u does, plus set math like [\p{L}--[a-z]]. Use u or v, not both.
      ystickyEach match must start exactly where the last one ended.
      dindicesGives the start and end of each group in the result.

      Turn on u when your text has emoji. Without it, JavaScript sees 😀 as two halves, so ^.$ does not match it.

      Catastrophic backtracking

      A tree of paths that splits again and again, growing out of a row of letters a that ends in b
      Each extra letter doubles the ways (a+)+ can try to match.

      A few patterns take time that doubles with every extra character. The classic case is ^(a+)+$ on a row of a's that ends in a b. The engine tries every way to share the a's between the inner + and the outer + before it gives up. For 30 letters that is about half a billion ways.

      This tester stops a test after 2 seconds. On a server there is no such stop, and a slow pattern can be used to block it, an attack called ReDoS. To avoid it, never put a repeat inside a repeat when both can match the same text, as in (a+)+ or (\w+\s?)*. Prefer a set like [^,]* over .*.

      Common patterns and where they fail

      Each of these patterns has gaps. "Try it" loads one into the tester with a text that shows where it fails.

      ForPatternWhere it failsLoad
      Email address/[\w.+-]+@[\w-]+(?:\.[\w-]+)+/gFinds most everyday addresses. It misses addresses with letters like é and quoted names, and it skips me@localhost, which works on some local networks. It does not check that the address is real.
      Web link/https?:\/\/[^\s<>"]+/gTakes a period or a bracket at the end of a sentence as part of the link. Misses links without http, like www.example.com.
      Date as 2026-11-07/\b(?<year>\d{4})-(?<month>0[1-9]|1[0-2])-(?<day>0[1-9]|[12]\d|3[01])\b/gChecks the month (01 to 12) and the day (01 to 31), but still takes 2026-02-31. Check real dates in your code.
      Number/-?\d+(?:\.\d+)?/gReads 1,250.50 as two numbers and 1.2.3 as two. Decimal commas, like 3,5 in much of Europe, are not covered.
      Hex color/#(?:[\da-f]{8}|[\da-f]{6}|[\da-f]{3,4})\b/giAlso takes words like #fade or #bad that use only the letters a to f.
      Phone number (US)/\(?\b\d{3}\)?[-. ]?\d{3}[-. ]?\d{4}\b/gOnly the ten digit North American form. Numbers from other countries have other lengths and groups.
      Doubled words/\b(\w+)\s+\1\b/giWorks only with the letters A to Z. With the i flag "The the" counts too, and the replacement keeps the first one.
      Spaces at line ends/[ \t]+$/gmNeeds the m flag, or only the very end of the text is checked. Spaces at the start of lines stay.
      Double spaces/ {2,}/gOnly plain spaces. Tabs and no break spaces stay; [ \t\u00A0]{2,} catches those too.
      Empty lines/^[ \t]*\r?\n/gmAn empty last line with no line break after it stays.
      HTML tags/<[^>]+>/gBreaks on a > inside an attribute or a comment. Never use it to make HTML safe; use a real HTML parser for that.
      IPv4 address/\b(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\b/gRejects numbers over 255. In 1.2.3.4.5 it still finds 1.2.3.4, and it knows nothing of IPv6.
      Words in any alphabet/\p{L}+(?:['’]\p{L}+)*/guNeeds the u flag. Splits words at a hyphen, and Chinese or Japanese text with no spaces counts as one long word.

      No pattern can prove that an email address or a date is real. Use the pattern to find likely matches, then check each one in your code. To run a pattern over a whole document, with undo and several rules in a row, use find and replace.

      Frequently asked questions

      Why does my regex work in Python but not here?

      Python and JavaScript read some signs differently. Named groups are (?P<name>...) in Python and (?<name>...) in JavaScript. \w matches é in Python but not in JavaScript. The table at the top of this article lists the rest.

      How do I match a dot, a bracket or a question mark?

      Put a backslash before it: \., \(, \[, \?. Inside a set like [.?] most signs are plain already, so no backslash is needed.

      Why does ^ only match at the start of the first line?

      Without the m flag, ^ means the start of the whole text and $ the very end. Turn on m to make them match at every line.

      What does "Pattern too slow" mean?

      The test took more than 2 seconds, so the tester stopped it. Look for a repeat inside a repeat, like (a+)+, and rewrite it as the section on catastrophic backtracking shows.

      How do I share a test?

      Press Copy link. The pattern, flags, test text and replacement go into the link after the # sign. Browsers do not send that part to a server, so only the person you send the link to sees the test.

      • Find and replaceFind and replace words in any text, with match case, whole words and regex.
      • Code editorWrite or paste HTML, CSS, JavaScript, JSON, Python, SQL and more with colors, line numbers and a format button.
      • JSON editorPaste JSON to format, minify or check it.
      • Encode and decodeEncode or decode text as Base64, URL encoding, HTML entities, Unicode escapes and hex.
      • Text cleanerPaste messy text and clean it in one click.
      • Sort linesSort lines A to Z, by number or by length.

      ↑ ↓ to choose, Enter to open, Esc to close