Regular Expressions 101

Save & Share

  • Regex Version: ver. 3
  • 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

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

/
/
gu

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 = "Authentication-results:.+?sender IP.+\\R?.+?mailfrom=(.+?);"; final String string = "Return-path: <JaneSmith@SomeDummyCo.com>\n" + "Received: from ms11p00im-qufv17093501.mac.com ([17.58.36.64])\n" + " by ms24534.mac.com\n" + " (Oracle Communications Messaging Server 8.0.1.3.20170906 64bit (built Sep 6\n" + " 2017)) with ESMTP id <0PE4008Z5RC0PLA0@ms24534.mac.com> for\n" + " JohnDoe@icloud.com; Mon, 27 Aug 2018 17:31:12 +0000 (GMT)\n" + "Original-recipient: rfc822;JohnDoe@icloud.com\n" + "Received: from NAM04-SN1-obe.outbound.protection.outlook.com\n" + " (mail-eopbgr700137.outbound.protection.outlook.com [40.107.70.137])\n" + " by ms11p00im-qufv17093501.me.com\n" + " (Oracle Communications Messaging Server 8.0.2.2.20180531 64bit (built May 31\n" + " 2018)) with ESMTPS id <0PE400K2IRBZ4F00@ms11p00im-qufv17093501.me.com> for\n" + " JohnDoe@icloud.com (ORCPT JohnDoe@icloud.com); Mon,\n" + " 27 Aug 2018 17:31:12 +0000 (GMT)\n" + "X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0\n" + " clxscore=1005 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0\n" + " bulkscore=0 classifier=clx:Deliver adjust=0 reason=mlx scancount=1\n" + " engine=8.0.1-1807170000 definitions=main-1808270184\n" + "X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,,\n" + " definitions=2018-08-27_07:,, signatures=0\n" + "Authentication-results: ms11p00im-qufv10093201.me.com; dmarc=none\n" + " header.from=apoemail.us\n" + "Authentication-results: ms11p00im-qufv10113901.me.com; spf=pass\n" + " (ms11p00im-qufv10113901.me.com: domain of JaneSmith@SomeDummyCo.com designates\n" + " 40.107.70.137 as permitted sender) smtp.mailfrom=JaneSmith@SomeDummyCo.com\n" + "Received-SPF: pass (ms11p00im-qufv10113901.me.com: domain of\n" + " JaneSmith@SomeDummyCo.com designates 40.107.70.137 as permitted sender)\n" + " receiver=ms11p00im-qufv10113901.me.com; client-ip=40.107.70.137;\n" + " helo=NAM04-SN1-obe.outbound.protection.outlook.com;\n" + " envelope-from=JaneSmith@SomeDummyCo.com\n" + "Authentication-results: ms11p00im-qufv17063001.me.com; dkim=pass (1024-bit key)\n" + " header.d=NETORGFT744019.onmicrosoft.com\n" + " header.i=@NETORGFT744019.onmicrosoft.com header.b=fYoFciKN\n" + "DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\n" + " d=NETORGFT744019.onmicrosoft.com; s=selector1-apoemail-us;\n" + " h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;\n" + " bh=ZUfrOM+P5LAWsuKD/Lnb58GuE4orISbImwlBF3a/vyc=;\n" + " b=fYoFciKNtylrXwhibBhDmgiw70cFEaUP4XADRpc2cfX3M/4o94Uc7kMGMdo7wj1KqH/d/ShRSn1YX36qzEnW5yA26XIloXj/bt7iZX2LN5boJlI6OaE6DFUIKivm2Cfvl4Q9wckPQRot76ogx/NeYCwfJvD/OgGybwJWjoLQQJo=\n" + "Received: from DM3PR19MB0521.namprd19.prod.outlook.com (10.164.248.145)\n" + " by DM3PR19MB0825.namprd19.prod.outlook.com (10.166.164.151)\n" + " with Microsoft SMTP Server\n" + " (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)\n" + " id 15.20.1080.14; Mon, 27 Aug 2018 17:31:09 +0000\n" + "Received: from DM3PR19MB0521.namprd19.prod.outlook.com\n" + " ([fe80::69c8:8da3:dc38:8caa]) by DM3PR19MB0521.namprd19.prod.outlook.com\n" + " ([fe80::69c8:8da3:dc38:8caa%5]) with mapi id 15.20.1080.015; Mon,\n" + " 27 Aug 2018 17:31:09 +0000\n" + "From: John Doe <JaneSmith@SomeDummyCo.com>\n" + "To: John Doe <JohnDoe@icloud.com>\n" + "Subject: AutoResponder - Acme Inc - New Client Questionnaire - - Steven\n" + " Plain Text TEST 03/12/1971\n" + "Thread-topic: AutoResponder - Acme Inc - New Client Questionnaire - -\n" + " Steven Plain Text TEST 03/12/1971\n" + "Thread-index: AQHUPiu+8RdF6Tdpg0SO88Zlg/iLzQ==\n" + "Date: Mon, 27 Aug 2018 17:31:09 +0000\n" + "Message-id: <D7A99F58.1E1AA%JaneSmith@SomeDummyCo.com>\n" + "Accept-Language: en-US\n" + "Content-language: en-US\n" + "X-MS-Has-Attach:\n" + "Authentication-results: spf=none (sender IP is )\n" + " smtp.mailfrom=JaneSmith@SomeDummyCo.com;\n" + "X-Originating-IP: [98.195.128.79]\n" + "X-Microsoft-Exchange-Diagnostics:\n"; final Pattern pattern = Pattern.compile(regex, Pattern.UNICODE_CASE); 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