Regular Expressions 101

Save & Share

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
No Match

/
/
gmi

Test String

Code Generator

Generated Code

#include <StringConstants.au3> ; to declare the Constants of StringRegExp #include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate Local $sRegex = "(?mi)(?:\sfrom\s+(?<from>[^\s*]+)[\s]*(?:(?:[\[\(.]?(?<fromh>.*?)?\.?\ *?[\[\(]?(?<fromip>(?:[0-9a-z]*?[\.\:]+[0-9a-z]*?)+)?[\)\]]+)?)(?=[\s;]+(?:by|with|via|id|for|;)\s*?)|\s+by\s+(?<byv>.*?)(?:\s+?\((?:[a-z\-\.]*?\s+)*?\[?(?<byip>(?:(?:[0-9a-z]*?[\.\:]+[0-9a-z]*?)+))*\]?\)?)?(?=[\s;]+(?:from|with|via|id|for|;)\s*?)|\s+via\s+(?<via>[a-z0-9\.\s]*?)(?=(?:\s*;|[\s]+(?:from|by|with|for|id|;))\s*?)|\swith\s+(?<protocol>(?:.|\s)*?)(?=(?:\s*;|[\s]+(?:from|by|via|for|id|;))\s*?)|\s+id\s+(?<id>[^\s;]+)(?=(?:\s*;|[\s]+(?:from|by|via|with|for|;))\s*?)|\s+for\s+<?(?<for>[^\s;>]+)>?(?=(?:\s*;|[\s]+(?:from|by|via|with|id|;))\s*?)|;\s+(?<date>[a-z]{3},\s+[0-9]{1,2}\s+[a-z]{3,4}\s+[0-9]{4}\s+[0-9]{2}\:[0-9]{2}\:[0-9]{2}\s+(?:-[0-9]{4}\s+)?(?:\([a-z]+\)|\+[0-9]{4}))?\n?)" Local $sString = "Received: from VE1PR01MB5599.eurprd01.prod.exchangelabs.com " & @CRLF & _ " (aze [2603:10a6:7:7c::43]) by HE1PR0102MB2714.eurprd01.prod.exchangelabs.com with HTTPS via HE1PR0402CA0054.EURPRD04.PROD.OUTLOOK.COM with toto; Thu, 9 Jan 2020 16:34:13 +0000" & @CRLF & _ "" & @CRLF & _ "Received: from relay-in.ohc.cu (relay-in.ohc.cu [127.0.0.1])" & @CRLF & _ " by relay-out.ohc.cu (Postfix) with ESMTP id 69EA722DD" & @CRLF & _ " for <some.email@some.domain>; Thu, 9 Jan 2020 11:29:43 -0500 (CST)" & @CRLF & _ "" & @CRLF & _ "Received: from correo.patrimonio.ohc.cu (unknown [192.168.229.20])" & @CRLF & _ " by relay-out.ohc.cu (Postfix) via hello with ESMTP id B83BA22F5" & @CRLF & _ " for <some.email@some.domain>; Thu, 9 Jan 2020 11:29:36 -0500 (CST)" & @CRLF & _ "" & @CRLF & _ "Received: from correoweb.patrimonio.ohc.cu (unknown [192.168.229.23])" & @CRLF & _ " by correo.patrimonio.ohc.cu (Postfix) with ESMTPA id EC62A232A00A;" & @CRLF & _ " Thu, 9 Jan 2020 11:39:53 -0500 (CST)" & @CRLF & _ "" & @CRLF & _ "Received: from VE1PR01MB5599.eurprd01.prod.exchangelabs.com" & @CRLF & _ " (2603:10a6:7:7c::43) by HE1PR0102MB2714.eurprd01.prod.exchangelabs.com with HTTPS via HE1PR0402CA0054.EURPRD04.PROD.OUTLOOK.COM; Thu, 9 Jan 2020 16:34:13" & @CRLF & _ " +0000" & @CRLF & _ "" & @CRLF & _ "Received: from VI1PR0102CA0029.eurprd01.prod.exchangelabs.com" & @CRLF & _ " (2603:10a6:802::42) by VE1PR01MB5599.eurprd01.prod.exchangelabs.com" & @CRLF & _ " (2603:10a6:803:11f::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2602.12; Thu, 9 Jan" & @CRLF & _ " 2020 16:34:13 +0000" & @CRLF & _ "" & @CRLF & _ "Received: from DB5EUR01FT034.eop-EUR01.prod.protection.outlook.com" & @CRLF & _ " (2a01:111:f400:7e02::203) by VI1PR0102CA0029.outlook.office365.com" & @CRLF & _ " (2603:10a6:802::42) with Microsoft SMTP Server (version=TLS1_2," & @CRLF & _ " cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2623.9 via Frontend" & @CRLF & _ " Transport; Thu, 9 Jan 2020 16:34:13 +0000" & @CRLF & _ "" & @CRLF & _ "Received: from relay-out.ohc.cu (200.55.138.44) by" & @CRLF & _ " DB5EUR01FT034.mail.protection.outlook.com (10.152.4.246) with Microsoft SMTP" & @CRLF & _ " Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id" & @CRLF & _ " 15.20.2623.9 via Frontend Transport; Thu, 9 Jan 2020 16:34:12 +0000" & @CRLF & _ "" & @CRLF & _ "Received: from relay-in.ohc.cu (relay-in.ohc.cu [127.0.0.1])" & @CRLF & _ " by relay-out.ohc.cu (Postfix) with ESMTP id 69EA722DD" & @CRLF & _ " for <some.email@some.domain>; Thu, 9 Jan 2020 11:29:43 -0500 (CST)" & @CRLF & _ "" & @CRLF & _ "Received: from relay-out.ohc.cu ([127.0.0.1])" & @CRLF & _ " by relay-in.ohc.cu (relay-in.ohc.cu [127.0.0.1]) (amavisd-new, port 10024)" & @CRLF & _ " with ESMTP id 7CZku5Y59vGC for <some.email@some.domain>;" & @CRLF & _ " Thu, 9 Jan 2020 11:29:38 -0500 (CST)" & @CRLF & _ "" & @CRLF & _ "Received: from correo.patrimonio.ohc.cu (unknown [192.168.229.20])" & @CRLF & _ " by relay-out.ohc.cu (Postfix) with ESMTP id B83BA22F5" & @CRLF & _ " for <some.email@some.domain>; Thu, 9 Jan 2020 11:29:36 -0500 (CST)" & @CRLF & _ "" & @CRLF & _ "Received: from localhost (localhost.localdomain [127.0.0.1])" & @CRLF & _ " by correo.patrimonio.ohc.cu (Postfix) with ESMTP id 65413232A001" & @CRLF & _ " for <some.email@some.domain>; Thu, 9 Jan 2020 11:40:05 -0500 (CST)" & @CRLF & _ "" & @CRLF & _ "Received: from correo.patrimonio.ohc.cu ([127.0.0.1])" & @CRLF & _ " by localhost (correo.patrimonio.ohc.cu [127.0.0.1]) (amavisd-new, port 10024)" & @CRLF & _ " with ESMTP id hNMp-6lHHtzH for <some.email@some.domain>;" & @CRLF & _ " Thu, 9 Jan 2020 11:40:05 -0500 (CST)" & @CRLF & _ "" & @CRLF & _ "Received: from correoweb.patrimonio.ohc.cu (unknown [192.168.229.23])" & @CRLF & _ " by correo.patrimonio.ohc.cu (Postfix) with ESMTPA id EC62A232A00A;" & @CRLF & _ " Thu, 9 Jan 2020 11:39:53 -0500 (CST)" Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYGLOBALFULLMATCH) Local $aFullArray[0] For $i = 0 To UBound($aArray) -1 _ArrayConcatenate($aFullArray, $aArray[$i]) Next $aArray = $aFullArray ; Present the entire match result _ArrayDisplay($aArray, "Result")

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 AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm