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

const regex = /(\r\n|\x80)(to|from):(([A-Za-z0-9 _."@-]+)?<([a-zA-Z0-9_.-]+@[a-zA-Z0-9_.]+)>)?\r\n)/gi; // Alternative syntax using RegExp constructor // const regex = new RegExp('(\\r\\n|\\x80)(to|from):(([A-Za-z0-9 _."@-]+)?<([a-zA-Z0-9_.-]+@[a-zA-Z0-9_.]+)>)?\\r\\n)', 'gi') const str = `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) Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1b89d47ffb6so11033645ad.2 for <test@recovery.silk.sc>; Fri, 14 Jul 2023 06:25:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689341135; x=1691933135; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=/78AA1pYoWos3oY8unmgOyrUao7Cpcjxa/I8Tp0cpGI=; b=LOp/017jnLGE1JykdOHW8u5oYpzZASc4EI+RvaXRjCqzP5oiOb+3+h5ATYWUmTg1mO mB6Pv1uXqzoXGsd4fGj+ymMFNHXeevnMZjhhNsb6aN4ehqO2icvB64P1P7Qc2kgmbiZc dN0q0E5dM4HWKIrN/cH5/Mo9L3R5yHd6uQEMD1HxeTd46FZF6a/Vg3SsQUf4iCGpM3Kd KmXz4ZNIvdHELIMdtcKFgwYF/dxk/oToY3BRD1b4m0v0mxSnMLeBdR/EYcdtpV4+VRiD +1KLRanyM+Udy0LLgFXV09ZXnA/iBXSMUaMuS2hwcrv7H0AwQUSQztisiUHQ7GEZs8wq BJdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689341135; x=1691933135; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=/78AA1pYoWos3oY8unmgOyrUao7Cpcjxa/I8Tp0cpGI=; b=VpP94CYKmyxu7iYb97AF+TtD5uqrfwy1SJijNL8E5+A8Fr3aVkMr7HkEjDqbDNn/JG 3fDRxhbIj/kpgdfA5BVFraHzKj5UnUZaqdsijSWLX5t4iRd8yYFtyuvgExMK3VsFqnnl Rl1nJJ2CZpB3i5H6fIkgAepd4BqrzoBoRxM7ogQBGDUxmYSJ0iaGwqNk4g6v0SmYube/ 5ny10Kru2GZsrePID3DfUchL7U8gDt+w+miJZLTVmNv8ZQfsA90T48MGlgwvICVelwbz M1hrDpBs+e3hxSbsDrKvwPuHZ9AFP5ecUJ91MIoT4HLcLx3BBgjRmc1ndwcXWgUzbmsw Ux+w== X-Gm-Message-State: ABy/qLaZujbLurcrIgoBn0zv3P/vwuj2SAFCy8I765SQCLExtFyhpSEB +v5HvBfK9XOn1Dg5gaKtqelOR8jDfPALaoO4c+4vh7CPXvM= X-Google-Smtp-Source: APBJJlH3GbxjOYy3EnhKuMkDF8gcHnoSawm5i0uOh/gh0Rnblwqcp7wccXzjRW9zHdMapdm561UHp3RaXg86VE8LOy4= X-Received: by 2002:a17:902:ec88:b0:1b7:fef7:d578 with SMTP id x8-20020a170902ec8800b001b7fef7d578mr3530576plg.41.1689341135072; Fri, 14 Jul 2023 06:25:35 -0700 (PDT) MIME-Version: 1.0 From: Amit Kumar <amitep0365@gmail.com> Date: Fri, 14 Jul 2023 18:55:23 +0530 Message-ID: <CAFPicqiRzZ8rc3MK3ySmekzRqNb_kGULC76Gd_y1hhYDUWhiSg@mail.gmail.com> Subject: Recover 0x71C7656EC7ab88b098defB751B7401B5f6d8976F with 0x71C7656EC7ab88b098defB751B7401B5f6d8976B To: test@recovery.silk.sc Content-Type: multipart/alternative; boundary="00000000000042b3bf06007262ab" --00000000000042b3bf06007262ab Content-Type: text/plain; charset="UTF-8" dkfgjblr; --00000000000042b3bf06007262ab Content-Type: text/html; charset="UTF-8" <div dir="ltr">dkfgjblr;</div> --00000000000042b3bf06007262ab-- `; // Reset `lastIndex` if this regex is defined globally // regex.lastIndex = 0; let m; while ((m = regex.exec(str)) !== null) { // This is necessary to avoid infinite loops with zero-width matches if (m.index === regex.lastIndex) { regex.lastIndex++; } // The result can be accessed through the `m`-variable. m.forEach((match, groupIndex) => { console.log(`Found match, group ${groupIndex}: ${match}`); }); }

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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions