Regular Expressions 101

Save & Share

  • Regex Version: ver. 2
  • 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
No Match

r"
"
g

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 = "addr=\"(([0-9]{1,3}[\\.]){3}[0-9]{1,3})\"" Local $sString = "<?xml version="1.0" encoding="UTF-8"?>" & @CRLF & _ "<!DOCTYPE nmaprun>" & @CRLF & _ "<?xml-stylesheet href="file:///usr/bin/../share/nmap/nmap.xsl" type="text/xsl"?>" & @CRLF & _ "<!-- Nmap 7.80 scan initiated Fri Oct 16 04:52:18 2020 as: nmap -O -oX xml_data.xml 45.33.49.119 -->" & @CRLF & _ "<nmaprun scanner="nmap" args="nmap -O -oX xml_data.xml 45.33.49.119" start="1602823938" startstr="Fri Oct 16 04:52:18 2020" version="7.80" xmloutputversion="1.04">" & @CRLF & _ "<scaninfo type="syn" protocol="tcp" numservices="1000" services="1,3-4,6-7,9,13,17,19-26,30,32-33,37,42-43,49,53,70,79-85,88-90,99-100,106,109-111,113,119,125,135,139,143-144,146,161,163,179,199,211-212,22>" & @CRLF & _ "<verbose level="0"/>" & @CRLF & _ "<debugging level="0"/>" & @CRLF & _ "<host starttime="1602823938" endtime="1602823972"><status state="up" reason="reset" reason_ttl="64"/>" & @CRLF & _ "<address addr="45.33.49.119" addrtype="ipv4"/>" & @CRLF & _ "<hostnames>" & @CRLF & _ "<hostname name="ack.nmap.org" type="PTR"/>" & @CRLF & _ "</hostnames>" & @CRLF & _ "<ports><extraports state="filtered" count="993">" & @CRLF & _ "<extrareasons reason="no-responses" count="993"/>" & @CRLF & _ "</extraports>" & @CRLF & _ "<port protocol="tcp" portid="22"><state state="open" reason="syn-ack" reason_ttl="51"/><service name="ssh" method="table" conf="3"/></port>" & @CRLF & _ "<port protocol="tcp" portid="25"><state state="open" reason="syn-ack" reason_ttl="51"/><service name="smtp" method="table" conf="3"/></port>" & @CRLF & _ "<port protocol="tcp" portid="70"><state state="closed" reason="reset" reason_ttl="51"/><service name="gopher" method="table" conf="3"/></port>" & @CRLF & _ "<port protocol="tcp" portid="80"><state state="open" reason="syn-ack" reason_ttl="50"/><service name="http" method="table" conf="3"/></port>" & @CRLF & _ "<port protocol="tcp" portid="113"><state state="closed" reason="reset" reason_ttl="51"/><service name="ident" method="table" conf="3"/></port>" & @CRLF & _ "<port protocol="tcp" portid="443"><state state="open" reason="syn-ack" reason_ttl="50"/><service name="https" method="table" conf="3"/></port>" & @CRLF & _ "<port protocol="tcp" portid="31337"><state state="closed" reason="reset" reason_ttl="51"/><service name="Elite" method="table" conf="3"/></port>" & @CRLF & _ "</ports>" & @CRLF & _ "<os><portused state="open" proto="tcp" portid="22"/>" & @CRLF & _ "<portused state="closed" proto="tcp" portid="70"/>" & @CRLF & _ "<osmatch name="HP P2000 G3 NAS device" accuracy="91" line="34647">" & @CRLF & _ "<osclass type="storage-misc" vendor="HP" osfamily="embedded" accuracy="91"><cpe>cpe:/h:hp:p2000_g3</cpe></osclass>" & @CRLF & _ "</osmatch>" & @CRLF & _ "<osmatch name="Linux 2.6.32" accuracy="90" line="55409">" & @CRLF & _ "<osclass type="general purpose" vendor="Linux" osfamily="Linux" osgen="2.6.X" accuracy="90"><cpe>cpe:/o:linux:linux_kernel:2.6.32</cpe></osclass>" & @CRLF & _ "</osmatch>" & @CRLF & _ "<osmatch name="Linux 2.6.32 - 3.1" accuracy="90" line="56315">" & @CRLF & _ "<osclass type="general purpose" vendor="Linux" osfamily="Linux" osgen="2.6.X" accuracy="90"><cpe>cpe:/o:linux:linux_kernel:2.6</cpe></osclass>" & @CRLF & _ "<osclass type="general purpose" vendor="Linux" osfamily="Linux" osgen="3.X" accuracy="90"><cpe>cpe:/o:linux:linux_kernel:3</cpe></osclass>" & @CRLF & _ "</osmatch>" & @CRLF & _ "<osmatch name="Ubiquiti AirMax NanoStation WAP (Linux 2.6.32)" accuracy="90" line="61488">" & @CRLF & _ "<osclass type="WAP" vendor="Linux" osfamily="Linux" osgen="2.6.X" accuracy="90"><cpe>cpe:/o:linux:linux_kernel:2.6.32</cpe></osclass>" & @CRLF & _ "<osclass type="WAP" vendor="Ubiquiti" osfamily="embedded" accuracy="90"><cpe>cpe:/h:ubnt:airmax_nanostation</cpe></osclass>" & @CRLF & _ "</osmatch>" & @CRLF & _ "<osmatch name="Linux 3.7" accuracy="90" line="65676">" & @CRLF & _ "<osclass type="general purpose" vendor="Linux" osfamily="Linux" osgen="3.X" accuracy="90"><cpe>cpe:/o:linux:linux_kernel:3.7</cpe></osclass>" & @CRLF & _ "</osmatch>" & @CRLF & _ "<osmatch name="Linux 2.6.32 - 3.13" accuracy="89" line="56411">" & @CRLF & _ "<osclass type="general purpose" vendor="Linux" osfamily="Linux" osgen="2.6.X" accuracy="89"><cpe>cpe:/o:linux:linux_kernel:2.6</cpe></osclass>" & @CRLF & _ "<osclass type="general purpose" vendor="Linux" osfamily="Linux" osgen="3.X" accuracy="89"><cpe>cpe:/o:linux:linux_kernel:3</cpe></osclass>" & @CRLF & _ "</osmatch>" & @CRLF & _ "<osmatch name="Linux 3.0 - 3.2" accuracy="89" line="62456">" & @CRLF & _ "<osclass type="general purpose" vendor="Linux" osfamily="Linux" osgen="3.X" accuracy="89"><cpe>cpe:/o:linux:linux_kernel:3</cpe></osclass>" & @CRLF & _ "</osmatch>" & @CRLF & _ "<osmatch name="Linux 3.3" accuracy="89" line="65197">" & @CRLF & _ "<osclass type="general purpose" vendor="Linux" osfamily="Linux" osgen="3.X" accuracy="89"><cpe>cpe:/o:linux:linux_kernel:3.3</cpe></osclass>" & @CRLF & _ "</osmatch>" & @CRLF & _ "<osmatch name="Infomir MAG-250 set-top box" accuracy="89" line="59437">" & @CRLF & _ "<osclass type="media device" vendor="Linux" osfamily="Linux" osgen="2.6.X" accuracy="89"><cpe>cpe:/o:linux:linux_kernel:2.6</cpe></osclass>" & @CRLF & _ "<osclass type="media device" vendor="Infomir" osfamily="embedded" accuracy="89"><cpe>cpe:/h:infomir:mag-250</cpe></osclass>" & @CRLF & _ "</osmatch>" & @CRLF & _ "<osmatch name="Ubiquiti Pico Station WAP (AirOS 5.2.6)" accuracy="88" line="102825">" & @CRLF & _ "<osclass type="WAP" vendor="Ubiquiti" osfamily="AirOS" osgen="5.X" accuracy="88"><cpe>cpe:/o:ubnt:airos:5.2.6</cpe></osclass>" & @CRLF & _ "</osmatch>" & @CRLF & _ "</os>" & @CRLF & _ "<uptime seconds="751775" lastboot="Wed Oct 7 12:03:18 2020"/>" & @CRLF & _ "<tcpsequence index="256" difficulty="Good luck!" values="5833A5A,D5206F79,8E66294D,8E3B0632,AC2DB44A,7F486476"/>" & @CRLF & _ "<ipidsequence class="All zeros" values="0,0,0,0,0,0"/>" & @CRLF & _ "<tcptssequence class="1000HZ" values="2CCF1F79,2CCF1FD4,2CCF2043,2CCF209E,2CCF2102,2CCF2164"/>" & @CRLF & _ "<times srtt="193340" rttvar="78390" to="506900"/>" & @CRLF & _ "</host>" & @CRLF & _ "<runstats><finished time="1602823973" timestr="Fri Oct 16 04:52:53 2020" elapsed="34.33" summary="Nmap done at Fri Oct 16 04:52:53 2020; 1 IP address (1 host up) scanned in 34.33 seconds" exit="success"/><>" & @CRLF & _ "</runstats>" & @CRLF & _ "</nmaprun>" 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