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

r"
"
gm

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 = "(?m)^(?![^a-zA-Z0-9])(?:(?![.]{2,})[a-zA-Z0-9_\-.])+(?<![.])@(?:(?![^a-zA-Z0-9])(?:[a-zA-Z0-9_\-])+(?<![^a-zA-Z0-9])\.)+[a-zA-Z]{2,}$" Local $sString = "email@example.com" & @CRLF & _ "email@111.222.333.fr" & @CRLF & _ "firstname.lastname@example.com" & @CRLF & _ "email@subdomain.example.com" & @CRLF & _ "123@gmail.com" & @CRLF & _ "123@51gmail62548.com" & @CRLF & _ "1234567890@example.com" & @CRLF & _ "a.defosseux@tbs-education.fr" & @CRLF & _ "email@example-one.com" & @CRLF & _ "email@example.name" & @CRLF & _ "email@example.museum" & @CRLF & _ "email@example.co.jp" & @CRLF & _ "firstname-lastname@example.com" & @CRLF & _ "test@test.com" & @CRLF & _ "ezf@aezf.fr.en" & @CRLF & _ "azer123@123.fr" & @CRLF & _ "a@a.bb" & @CRLF & _ "a@a.ccc" & @CRLF & _ "a@bb.bb" & @CRLF & _ "a.a@bb.bb" & @CRLF & _ "a.a.a@bb.bb" & @CRLF & _ "a.a.a@a.bb.bb" & @CRLF & _ "a.a.a.a@a.a.bb" & @CRLF & _ "a.a.a.a@a.bb.bb" & @CRLF & _ "a.a.a.a@a.bb.ccc" & @CRLF & _ "a.bb.a.a@a.bb.ccc" & @CRLF & _ "a--a.a@a.bb.ccc" & @CRLF & _ "a.defosseux@tbs-education.x.fr" & @CRLF & _ "a.defosseux@tbs-education.x.y.fr" & @CRLF & _ "a.defosseux@tbs-education.x-e.y.fr" & @CRLF & _ "email@example-one.com" & @CRLF & _ "ema.il@example.com" & @CRLF & _ "e.ma.il@example.com" & @CRLF & _ "ema-il@example.com" & @CRLF & _ "e-ma-il@example.com" & @CRLF & _ "ema--il@example.com" & @CRLF & _ "em_ail@example.com" & @CRLF & _ "em__ail@example.com" & @CRLF & _ "6email@example.com" & @CRLF & _ "email6@example.com" & @CRLF & _ "6email6@example.com" & @CRLF & _ "test-test@x.fr" & @CRLF & _ "tes-t-test@x.fr" & @CRLF & _ "yasmina.achak@e.rascol.net" & @CRLF & _ "yasmina.achak@e.rascol.net.aezr.azerz.azer.azreezr.azeraez.azer" & @CRLF & _ "yasmina.achak@e.rascol.barce" & @CRLF & _ "yasmina.achak@e.rascol.bar" & @CRLF & _ "yasmina.achak@e.ba" & @CRLF & _ "sarah_benabdell@yahoo.fr" & @CRLF & _ "sarah__benabdellah@yahoo.fr" & @CRLF & _ "sarah---benabdellah@yahoo.fr" & @CRLF & _ "sarah___---benabdellah@yahoo.fr" & @CRLF & _ "marieagnes.paul@off---white.com" & @CRLF & _ "a.a@bb--bb.ccc" & @CRLF & _ "a.a@bb--bb.a.ccc" & @CRLF & _ "a_a@a.bb" & @CRLF & _ "a_a@a.bb" & @CRLF & _ "email-@example.com" & @CRLF & _ "email_@example.com" & @CRLF & _ "a_@a.bb" & @CRLF & _ "a._@a.bb" & @CRLF & _ "" & @CRLF & _ "a@ccc" & @CRLF & _ "#@%^%#$@#$@#.com" & @CRLF & _ "@example.com" & @CRLF & _ "Joe Smith <email@example.com>" & @CRLF & _ "email.example.com" & @CRLF & _ "email@example@example.com" & @CRLF & _ "email.@example.com" & @CRLF & _ "email..email@example.com" & @CRLF & _ "あいうえお@example.com" & @CRLF & _ "email@example.com (Joe Smith)" & @CRLF & _ "email@example" & @CRLF & _ "email@-example.com" & @CRLF & _ "email@111.222.333.44444" & @CRLF & _ "email@example..com" & @CRLF & _ "a..reds@free.fr" & @CRLF & _ "Abc..123@example.com" & @CRLF & _ "”(),:;<>[\]@example.com" & @CRLF & _ "just”not”right@example.com" & @CRLF & _ "this\ is"really"not\allowed@example.com" & @CRLF & _ "firstname+lastname@example.com" & @CRLF & _ "email@123.123.123.123" & @CRLF & _ "email@[123.123.123.123]" & @CRLF & _ ""email"@example.com" & @CRLF & _ "_______@example.com" & @CRLF & _ "much."more\ unusual"@example.com" & @CRLF & _ "very.unusual.”@”.unusual.com@example.com" & @CRLF & _ "very.”(),:;<>[]”.VERY.”very@\\ "very”.unusual@strange.example.com" & @CRLF & _ "azer aezr@test.com" & @CRLF & _ "zaetazfe.faezf" & @CRLF & _ "af@ezfezf" & @CRLF & _ "ez#!~f@aezf.fr" & @CRLF & _ "azefé@test.com" & @CRLF & _ "aze@zaé.com" & @CRLF & _ "a@a.a" & @CRLF & _ "a.a@a.a" & @CRLF & _ "a.a@a.a.a" & @CRLF & _ "a.a.a.a@a.a.a" & @CRLF & _ "a.a.a.a@a.a.a.a" & @CRLF & _ "a..a.a@a.bb.ccc" & @CRLF & _ "a.é@b.fr" & @CRLF & _ "azer.@fr" & @CRLF & _ ".azer@fr" & @CRLF & _ "a.defosseux@tbs-education-.fr" & @CRLF & _ "a.defosseux@-tbs-education.fr" & @CRLF & _ "a.defosseux@-tbs-education-.fr" & @CRLF & _ "a.defosseux@1234tbs-education.-x-.fr" & @CRLF & _ ".email@example.com" & @CRLF & _ ".email.@example.com" & @CRLF & _ "email.@example.com" & @CRLF & _ "ema..il@example.com" & @CRLF & _ "-email@example.com" & @CRLF & _ "-email-@example.com" & @CRLF & _ "_email@example.com" & @CRLF & _ "_email_@example.com" & @CRLF & _ "_em_ail_@example.com" & @CRLF & _ "_em__ail_@example.com" & @CRLF & _ "yaémina.achak@e.rascol.net" & @CRLF & _ ".-y__as-min-.@eerez.fr" & @CRLF & _ "yasmina.achak@e.b" & @CRLF & _ "yasmina.achak@e....bar" & @CRLF & _ "_a_@a.bb" & @CRLF & _ "_a@a.bb" & @CRLF & _ "_.a@a.bb" & @CRLF & _ "_.a._@a.bb" & @CRLF & _ "a@_a.bb" & @CRLF & _ "a@a_.bb" & @CRLF & _ "a@_a_.bb" & @CRLF & _ "a@a._bb_.ccc" & @CRLF & _ "a@a.__a__a__.ccc" & @CRLF & _ "a@a.__.bb.ccc" 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