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

/
/
gumi

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 = "(?umi)(?s)(?<=start).*?(?=end)" Local $sString = "Match all characters between two strings with dotall mode to match across line breaks" & @CRLF & _ "" & @CRLF & _ "Duis sem mi, rhoncus ut enim quis, ultricies posuere libero." & @CRLF & _ "Etiam et euismod dolor, at ornare lorem." & @CRLF & _ "Praesent iaculis pellentesque felis, sit amet interdum ex ultricies id." & @CRLF & _ "Nam eu mattis nisi." & @CRLF & _ "Sed et odio risus." & @CRLF & _ "Proin fermentum in justo non consequat." & @CRLF & _ "Pellentesque pellentesque augue sed erat porta gravida." & @CRLF & _ "In a magna at metus suscipit sodales non eget massa." & @CRLF & _ "Maecenas eu turpis non nisl semper ultricies." & @CRLF & _ "Duis rhoncus imperdiet sapien, vitae posuere erat tempor id." & @CRLF & _ "Vestibulum in enim fermentum purus tempor maximus tempus quis ex." & @CRLF & _ "Maecenas vitae felis ac elit semper blandit." & @CRLF & _ "Suspendisse neque eros, vestibulum nec ultrices at, sagittis eget ex." & @CRLF & _ "Aenean feugiat libero nunc, sit amet commodo turpis tristique luctus." & @CRLF & _ "Sed sodales diam at urna viverra, nec ultrices enim imperdiet." & @CRLF & _ "startLorem ipsum dolor sit amet, consectetur adipiscing elit." & @CRLF & _ "Nulla velit diam, vehicula eget nunc at, aliquet mattis velit." & @CRLF & _ "Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos." & @CRLF & _ "Nam quis sollicitudin augue." & @CRLF & _ "Maecenas a auctor nibh." & @CRLF & _ "Pellentesque aliquam nulla sit amet posuere laoreet." & @CRLF & _ "Nunc lorem massa, vehicula ac vehicula ac, varius vel est." & @CRLF & _ "Proin sed mattis dolor." & @CRLF & _ "Cras quis enim non nisl ultrices rhoncus in ut nisl." & @CRLF & _ "endCurabitur venenatis ullamcorper ullamcorper." & @CRLF & _ "Praesent in mi non mi bibendum lobortis at vel est." & @CRLF & _ "Mauris luctus varius justo, non rhoncus sem tristique quis." & @CRLF & _ "Aenean ac metus commodo felis pharetra dapibus." & @CRLF & _ "Integer hendrerit, enim ac varius sagittis, ipsum lacus euismod elit, sed sagittis tortor purus nec sapien." & @CRLF & _ "Morbi luctus risus quam, nec imperdiet nibh pulvinar id." & @CRLF & _ "Pellentesque pretium posuere ligula, id ullamcorper sapien placerat at." & @CRLF & _ "Nulla mattis tristique nisi id ornare." & @CRLF & _ "Cras at orci magna." & @CRLF & _ "Praesent interdum id est vitae feugiat." & @CRLF & _ "Praesent vulputate, tortor at eleifend venenatis, leo turpis malesuada mauris, non lobortis urna velit fringilla lacus." 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