Regular Expressions 101

Save & Share

  • Regex Version: ver. 4
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests (1)

Tools

Sponsors
There are currently no sponsors. Become a sponsor today!
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • A single character of: a, b or c
    [abc]
  • A character except: a, b or c
    [^abc]
  • A character in the range: a-z
    [a-z]
  • A character not in the range: a-z
    [^a-z]
  • A character in the range: a-z or A-Z
    [a-zA-Z]
  • Any single character
    .
  • Alternate - match either a or b
    a|b
  • Any whitespace character
    \s
  • Any non-whitespace character
    \S
  • Any digit
    \d
  • Any non-digit
    \D
  • Any word character
    \w
  • Any non-word character
    \W
  • Non-capturing group
    (?:...)
  • Capturing group
    (...)
  • Zero or one of a
    a?
  • Zero or more of a
    a*
  • One or more of a
    a+
  • Exactly 3 of a
    a{3}
  • 3 or more of a
    a{3,}
  • Between 3 and 6 of a
    a{3,6}
  • Start of string
    ^
  • End of string
    $
  • A word boundary
    \b
  • Non-word boundary
    \B

Regular Expression
No Match

/
/
gi

Test String

Code Generator

Generated Code

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "(\\r\\n|\\x80)(to|from):(([A-Za-z0-9 _.\"@-]+)?<([a-zA-Z0-9_.-]+@[a-zA-Z0-9_.]+)>)?\\r\\n)"; final String string = "Received: from mail-pl1-f170.google.com (mxd [209.85.214.170]) by mx.sendgrid.net with ESMTP id wvYfqqNwSdSZ_ZVHjbLYmQ for <test@recovery.silk.sc>; Fri, 14 Jul 2023 13:25:35.971 +0000 (UTC)\n" + "Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1b89d47ffb6so11033645ad.2\n" + " for <test@recovery.silk.sc>; Fri, 14 Jul 2023 06:25:35 -0700 (PDT)\n" + "DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\n" + " d=gmail.com; s=20221208; t=1689341135; x=1691933135;\n" + " h=to:subject:message-id:date:from:mime-version:from:to:cc:subject\n" + " :date:message-id:reply-to;\n" + " bh=/78AA1pYoWos3oY8unmgOyrUao7Cpcjxa/I8Tp0cpGI=;\n" + " b=LOp/017jnLGE1JykdOHW8u5oYpzZASc4EI+RvaXRjCqzP5oiOb+3+h5ATYWUmTg1mO\n" + " mB6Pv1uXqzoXGsd4fGj+ymMFNHXeevnMZjhhNsb6aN4ehqO2icvB64P1P7Qc2kgmbiZc\n" + " dN0q0E5dM4HWKIrN/cH5/Mo9L3R5yHd6uQEMD1HxeTd46FZF6a/Vg3SsQUf4iCGpM3Kd\n" + " KmXz4ZNIvdHELIMdtcKFgwYF/dxk/oToY3BRD1b4m0v0mxSnMLeBdR/EYcdtpV4+VRiD\n" + " +1KLRanyM+Udy0LLgFXV09ZXnA/iBXSMUaMuS2hwcrv7H0AwQUSQztisiUHQ7GEZs8wq\n" + " BJdg==\n" + "X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\n" + " d=1e100.net; s=20221208; t=1689341135; x=1691933135;\n" + " h=to:subject:message-id:date:from:mime-version:x-gm-message-state\n" + " :from:to:cc:subject:date:message-id:reply-to;\n" + " bh=/78AA1pYoWos3oY8unmgOyrUao7Cpcjxa/I8Tp0cpGI=;\n" + " b=VpP94CYKmyxu7iYb97AF+TtD5uqrfwy1SJijNL8E5+A8Fr3aVkMr7HkEjDqbDNn/JG\n" + " 3fDRxhbIj/kpgdfA5BVFraHzKj5UnUZaqdsijSWLX5t4iRd8yYFtyuvgExMK3VsFqnnl\n" + " Rl1nJJ2CZpB3i5H6fIkgAepd4BqrzoBoRxM7ogQBGDUxmYSJ0iaGwqNk4g6v0SmYube/\n" + " 5ny10Kru2GZsrePID3DfUchL7U8gDt+w+miJZLTVmNv8ZQfsA90T48MGlgwvICVelwbz\n" + " M1hrDpBs+e3hxSbsDrKvwPuHZ9AFP5ecUJ91MIoT4HLcLx3BBgjRmc1ndwcXWgUzbmsw\n" + " Ux+w==\n" + "X-Gm-Message-State: ABy/qLaZujbLurcrIgoBn0zv3P/vwuj2SAFCy8I765SQCLExtFyhpSEB\n" + " +v5HvBfK9XOn1Dg5gaKtqelOR8jDfPALaoO4c+4vh7CPXvM=\n" + "X-Google-Smtp-Source: APBJJlH3GbxjOYy3EnhKuMkDF8gcHnoSawm5i0uOh/gh0Rnblwqcp7wccXzjRW9zHdMapdm561UHp3RaXg86VE8LOy4=\n" + "X-Received: by 2002:a17:902:ec88:b0:1b7:fef7:d578 with SMTP id\n" + " x8-20020a170902ec8800b001b7fef7d578mr3530576plg.41.1689341135072; Fri, 14 Jul\n" + " 2023 06:25:35 -0700 (PDT)\n" + "MIME-Version: 1.0\n" + "From: Amit Kumar <amitep0365@gmail.com>\n" + "Date: Fri, 14 Jul 2023 18:55:23 +0530\n" + "Message-ID: <CAFPicqiRzZ8rc3MK3ySmekzRqNb_kGULC76Gd_y1hhYDUWhiSg@mail.gmail.com>\n" + "Subject: Recover 0x71C7656EC7ab88b098defB751B7401B5f6d8976F with 0x71C7656EC7ab88b098defB751B7401B5f6d8976B\n" + "To: test@recovery.silk.sc\n" + "Content-Type: multipart/alternative; boundary=\"00000000000042b3bf06007262ab\"\n\n" + "--00000000000042b3bf06007262ab\n" + "Content-Type: text/plain; charset=\"UTF-8\"\n\n" + "dkfgjblr;\n\n" + "--00000000000042b3bf06007262ab\n" + "Content-Type: text/html; charset=\"UTF-8\"\n\n" + "<div dir=\"ltr\">dkfgjblr;</div>\n\n" + "--00000000000042b3bf06007262ab--\n"; final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html