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

/
/
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)((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]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/([0-9]+))|((([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/([0-9]+))" Local $sString = "<?xml version="1.0" encoding="utf-8"?>" & @CRLF & _ "<reg:registerSocResources updateTime="2023-08-23T17:00:00+03:00" formatVersion="1.0" xmlns:reg="http://rkn.gov.ru/register/socResources" xmlns:tns="http://rkn.gov.ru/register/socResources">" & @CRLF & _ " <content id="1" hash="c74d571742a6c706828b803d5190e566" includeTime="2022-01-26T22:00:00+03:00">" & @CRLF & _ " <resourceName><![CDATA[Единый портал государственных и муниципальных услуг (Госуслуги)]]></resourceName>" & @CRLF & _ " <domain><![CDATA[gosuslugi.ru]]></domain>" & @CRLF & _ " <ipSubnet>37.220.160.0/21</ipSubnet>" & @CRLF & _ " <ipSubnet>46.235.184.0/21</ipSubnet>" & @CRLF & _ " <ipSubnet>93.93.88.0/21</ipSubnet>" & @CRLF & _ " <ipSubnet>78.41.104.0/21</ipSubnet>" & @CRLF & _ " <ipSubnet>185.17.168.0/22</ipSubnet>" & @CRLF & _ " <ipSubnet>212.193.144.0/20</ipSubnet>" & @CRLF & _ " <ipSubnet>195.208.30.60/30</ipSubnet>" & @CRLF & _ " <ipSubnet>195.209.64.0/21</ipSubnet>" & @CRLF & _ " <ipSubnet>195.209.80.0/20</ipSubnet>" & @CRLF & _ " <ipSubnet>195.208.64.0/20</ipSubnet>" & @CRLF & _ " <ipSubnet>195.209.75.0/25</ipSubnet>" & @CRLF & _ " <ipSubnet>185.38.204.18/32</ipSubnet>" & @CRLF & _ " <ipSubnet>109.207.0.0/20</ipSubnet>" & @CRLF & _ " <ipSubnet>213.59.192.0/18</ipSubnet>" & @CRLF & _ " </content>" & @CRLF & _ " <content id="2" hash="45fcc3ee99b66673c1de92809d7ea403" includeTime="2022-01-26T22:00:00+03:00">" & @CRLF & _ " <resourceName><![CDATA[Социальная сеть "ВКонтакте"]]></resourceName>" & @CRLF & _ " <domain><![CDATA[vk.com]]></domain>" & @CRLF & _ " <ipSubnet>5.181.61.0/24</ipSubnet>" & @CRLF & _ " <ipSubnet>79.137.139.0/24</ipSubnet>" & @CRLF & _ " <ipSubnet>79.137.164.0/24</ipSubnet>" & @CRLF & _ " <ipSubnet>79.137.180.0/24</ipSubnet>" & @CRLF & _ " <ipSubnet>79.137.183.0/24</ipSubnet>" & @CRLF & _ " <ipSubnet>87.240.128.0/18</ipSubnet>" & @CRLF & _ " <ipSubnet>93.186.224.0/20</ipSubnet>" & @CRLF & _ " <ipSubnet>95.142.192.0/20</ipSubnet>" & @CRLF & _ " <ipSubnet>95.213.0.0/17</ipSubnet>" & @CRLF & _ " <ipSubnet>185.32.248.0/22</ipSubnet>" & @CRLF & _ " <ipSubnet>185.226.52.0/22</ipSubnet>" & @CRLF & _ " <ipSubnet>45.136.20.0/22</ipSubnet>" & @CRLF & _ " <ipSubnet>95.163.39.80/29</ipSubnet>" & @CRLF & _ " <ipSubnet>193.203.40.0/22</ipSubnet>" & @CRLF & _ " <ipSubnet>5.61.20.180/31</ipSubnet>" & @CRLF & _ " <ipSubnet>5.61.20.196/30</ipSubnet>" & @CRLF & _ " <ipSubnet>5.61.20.248/29</ipSubnet>" & @CRLF & _ " <ipSubnet>5.61.23.186/31</ipSubnet>" & @CRLF & _ " <ipSubnet>5.61.23.228/31</ipSubnet>" & @CRLF & _ " <ipSubnet>5.61.23.248/30</ipSubnet>" & @CRLF & _ " <ipSubnet>185.16.247.226/31</ipSubnet>" & @CRLF & _ " <ipSubnet>185.100.104.4/30</ipSubnet>" & @CRLF & _ " <ipSubnet>185.100.104.44/30</ipSubnet>" & @CRLF & _ " <ipSubnet>185.100.104.48/29</ipSubnet>" & @CRLF & _ " <ipSubnet>185.100.104.132/30</ipSubnet>" & @CRLF & _ " <ipSubnet>185.100.105.24/29</ipSubnet>" & @CRLF & _ " <ipSubnet>185.100.105.64/30</ipSubnet>" & @CRLF & _ " <ipSubnet>185.100.105.132/30</ipSubnet>" & @CRLF & _ " <ipSubnet>185.100.105.192/29</ipSubnet>" & @CRLF & _ " <ipSubnet>185.100.105.200/30</ipSubnet>" & @CRLF & _ " <ipSubnet>217.20.158.34/31</ipSubnet>" & @CRLF & _ " <ipSubnet>5.101.40.2/32</ipSubnet>" & @CRLF & _ " <ipSubnet>217.20.152.213/32</ipSubnet>" & @CRLF & _ " <ipSubnet>217.20.156.158/32</ipSubnet>" & @CRLF & _ " <ipSubnet>217.20.156.18/32</ipSubnet>" & @CRLF & _ " <ipSubnet>217.20.155.24/32</ipSubnet>" & @CRLF & _ " <ipSubnet>217.20.147.23/32</ipSubnet>" & @CRLF & _ " <ipSubnet>95.163.56.192/27</ipSubnet>" & @CRLF & _ " <ipSubnet>95.163.41.200/30</ipSubnet>" & @CRLF & _ " <ipSubnet>5.61.16.0/21</ipSubnet>" & @CRLF & _ " <ipSubnet>185.16.148.0/22</ipSubnet>" & @CRLF & _ " <ipSubnet>185.16.244.0/22</ipSubnet>" & @CRLF & _ " <ipSubnet>217.20.144.0/20</ipSubnet>" & @CRLF & _ " <ipSubnet>87.240.160.0/26</ipSubnet>" & @CRLF & _ " <ipSubnet>95.142.201.192/27</ipSubnet>" & @CRLF & _ " <ipSubnet>95.142.202.0/27</ipSubnet>" & @CRLF & _ " <ipSubnet>95.142.203.192/27</ipSubnet>" & @CRLF & _ " <ipSubnet>95.142.206.192/27</ipSubnet>" & @CRLF & _ " <ipSubnet>185.32.249.192/27</ipSubnet>" & @CRLF & _ " <ipSubnet>185.32.250.192/27</ipSubnet>" & @CRLF & _ " <ipSubnet>185.32.251.192/27</ipSubnet>" & @CRLF & _ " <ipSubnet>185.100.104.0/22</ipSubnet>" & @CRLF & _ " </content>" & @CRLF & _ " <ipv6Subnet>2001:0db8:11a3:09d7::/64</ipv6Subnet>" 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