Regular Expressions 101

Save & Share

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

/
/
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)\b(127\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|0?10\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|172\.0?1[6-9]\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|172\.0?2[0-9]\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|172\.0?3[01]\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|192\.168\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|169\.254\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|::1|[fF][cCdD][0-9a-fA-F]{2}(?:[:][0-9a-fA-F]{0,4}){0,7}|[fF][eE][89aAbB][0-9a-fA-F](?:[:][0-9a-fA-F]{0,4}){0,7})(?:\/([789]|1?[0-9]{2}))?\b" Local $sString = "# loopback" & @CRLF & _ "127.0.0.0" & @CRLF & _ "127.0.0.0000 # only three digits supported here" & @CRLF & _ "" & @CRLF & _ "# A" & @CRLF & _ "10.0.0.1/10" & @CRLF & _ "10.255.22.33" & @CRLF & _ "" & @CRLF & _ "# B" & @CRLF & _ "172.17.100.155/32" & @CRLF & _ "" & @CRLF & _ "# C" & @CRLF & _ "192.168.1.1" & @CRLF & _ "192.168.1.255" & @CRLF & _ "" & @CRLF & _ "# IPv6" & @CRLF & _ "fc00:833e:d648:f196:5c6c:1d9a:a14b:0d59" & @CRLF & _ "fc01:67e5::6a66:34a7" & @CRLF & _ "FC02:5fcf:e093:bb10:ce77:b5c9::/112" & @CRLF & _ "fc03:49bd:b7c1:5685:fa0a:87e9::2/128" & @CRLF & _ "fc04:::2 hmpf" & @CRLF & _ "# Public IP addresses" & @CRLF & _ "0de9:b022:883f:2c3c:7dba:a184:7576:4531" & @CRLF & _ "04e4:e53b:0c2f:2990:27ad:0464:6dd3:b6b3" & @CRLF & _ "0319:3b4a:546e:d480:4814:f885:3396:bba2" & @CRLF & _ "5394:03f5:606f:273e:e343:d94a:610a:3f2e" & @CRLF & _ "63cd:ad1f:7ffb:62c7:cc17:6e20:9b59:2f7d" & @CRLF & _ "" & @CRLF & _ "# More "crap"" & @CRLF & _ "30.168.1.255.1" & @CRLF & _ "127.1" & @CRLF & _ "192.168.1.256" & @CRLF & _ "-1.2.3.4" & @CRLF & _ "1.1.1.1." & @CRLF & _ "3...3" & @CRLF & _ "255.255.255.255" & @CRLF & _ "0.0.0.0" & @CRLF & _ "1.1.1.01" & @CRLF & _ "192.99.16.30" & @CRLF & _ "" & @CRLF & _ "# decimal vs. octal mix" & @CRLF & _ "172.032.33.33" & @CRLF & _ "172.033.33.33" & @CRLF & _ "" & @CRLF & _ "# octal - not supported here" & @CRLF & _ "0254.0021.0062.0041" & @CRLF & _ "" & @CRLF & _ "# link-local addresses IPv4" & @CRLF & _ "169.254.1.0" & @CRLF & _ "169.254.254.255" & @CRLF & _ "" & @CRLF & _ "# link-local addresses IPv6" & @CRLF & _ "fe90:1234::/64" & @CRLF & _ "feaf:ffff::/128" & @CRLF & _ "febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff" & @CRLF & _ "" 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