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
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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

/
/
g

Test String

Substitution

Processing...

Code Generator

Generated Code

#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox Local $sRegex = "(\[.*\])(=>?)\s+(\w+[\(\)\d+\.]+)\s+?(\".*\"|\{[\s\w]+\})?" Local $sString = "array(40) {" & @CRLF & _ " ["HTTP_AUTHORIZATION"]=>" & @CRLF & _ " string(0) """ & @CRLF & _ " ["HTTP_HOST"]=>" & @CRLF & _ " string(12) "galtrade.loc"" & @CRLF & _ " ["HTTP_CONNECTION"]=>" & @CRLF & _ " string(10) "keep-alive"" & @CRLF & _ " ["HTTP_PRAGMA"]=>" & @CRLF & _ " string(8) "no-cache"" & @CRLF & _ " ["HTTP_CACHE_CONTROL"]=>" & @CRLF & _ " string(8) "no-cache"" & @CRLF & _ " ["HTTP_UPGRADE_INSECURE_REQUESTS"]=>" & @CRLF & _ " string(1) "1"" & @CRLF & _ " ["HTTP_USER_AGENT"]=>" & @CRLF & _ " string(142) "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 YaBrowser/19.3.0.2485 Yowser/2.5 Safari/537.36"" & @CRLF & _ " ["HTTP_ACCEPT"]=>" & @CRLF & _ " string(85) "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"" & @CRLF & _ " ["HTTP_ACCEPT_ENCODING"]=>" & @CRLF & _ " string(13) "gzip, deflate"" & @CRLF & _ " ["HTTP_ACCEPT_LANGUAGE"]=>" & @CRLF & _ " string(11) "ru,en;q=0.9"" & @CRLF & _ " ["HTTP_COOKIE"]=>" & @CRLF & _ " string(59) "fdafa396c9597e51e294ef0cc64573a0=c0ntndm6dh8bg3vk901nrs1a05"" & @CRLF & _ " ["PATH"]=>" & @CRLF & _ " string(502) "c:\ospanel\modules\php\PHP-5.6\ext;c:\ospanel\modules\php\PHP-5.6\pear;c:\ospanel\modules\php\PHP-5.6\pear\bin;c:\ospanel\modules\php\PHP-5.6;c:\ospanel\modules\imagemagick;c:\ospanel\modules\wget\bin;c:\ospanel\modules\git;c:\ospanel\modules\git\bin;c:\ospanel\modules\git\mingw\bin;c:\ospanel\modules\git\cmd;c:\ospanel\modules\database\MySQL-5.6\bin;c:\ospanel\modules\http\Apache-2.4\bin;c:\ospanel\modules\http\Apache-2.4;C:\Windows\system32;C:\Windows;C:\Windows\system32\Wbem;C:\Windows\SysWOW64"" & @CRLF & _ " ["SystemRoot"]=>" & @CRLF & _ " string(10) "C:\Windows"" & @CRLF & _ " ["COMSPEC"]=>" & @CRLF & _ " string(27) "C:\Windows\system32\cmd.exe"" & @CRLF & _ " ["PATHEXT"]=>" & @CRLF & _ " string(53) ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC"" & @CRLF & _ " ["WINDIR"]=>" & @CRLF & _ " string(10) "C:\Windows"" & @CRLF & _ " ["SERVER_SIGNATURE"]=>" & @CRLF & _ " string(0) """ & @CRLF & _ " ["SERVER_SOFTWARE"]=>" & @CRLF & _ " string(6) "Apache"" & @CRLF & _ " ["SERVER_NAME"]=" & @CRLF & _ " string(12) "galtrade.loc"" & @CRLF & _ " ["SERVER_ADDR"]=>" & @CRLF & _ " string(9) "127.0.0.1"" & @CRLF & _ " ["SERVER_PORT"]=>" & @CRLF & _ " string(2) "80"" & @CRLF & _ " ["REMOTE_ADDR"]=>" & @CRLF & _ " string(9) "127.0.0.1"" & @CRLF & _ " ["DOCUMENT_ROOT"]=>" & @CRLF & _ " string(23) "H:/Domains/galtrade.loc"" & @CRLF & _ " ["REQUEST_SCHEME"]=>" & @CRLF & _ " string(4) "http"" & @CRLF & _ " ["CONTEXT_PREFIX"]=>" & @CRLF & _ " string(0) """ & @CRLF & _ " ["CONTEXT_DOCUMENT_ROOT"]=>" & @CRLF & _ " string(23) "H:/Domains/galtrade.loc"" & @CRLF & _ " ["SERVER_ADMIN"]=>" & @CRLF & _ " string(18) "[no address given]"" & @CRLF & _ " ["SCRIPT_FILENAME"]=>" & @CRLF & _ " string(33) "H:/Domains/galtrade.loc/index.php"" & @CRLF & _ " ["REMOTE_PORT"]=>" & @CRLF & _ " string(5) "45846"" & @CRLF & _ " ["GATEWAY_INTERFACE"]=>" & @CRLF & _ " string(7) "CGI/1.1"" & @CRLF & _ " ["SERVER_PROTOCOL"]=>" & @CRLF & _ " string(8) "HTTP/1.1"" & @CRLF & _ " ["REQUEST_METHOD"]=>" & @CRLF & _ " string(3) "GET"" & @CRLF & _ " ["QUERY_STRING"]=>" & @CRLF & _ " string(0) """ & @CRLF & _ " ["REQUEST_URI"]=>" & @CRLF & _ " string(1) "/"" & @CRLF & _ " ["SCRIPT_NAME"]=>" & @CRLF & _ " string(10) "/index.php"" & @CRLF & _ " ["PHP_SELF"]=>" & @CRLF & _ " string(10) "/index.php"" & @CRLF & _ " ["REQUEST_TIME_FLOAT"]=>" & @CRLF & _ " float(1552820558.246)" & @CRLF & _ " ["REQUEST_TIME"]=>" & @CRLF & _ " int(1552820558)" & @CRLF & _ " ["argv"]=>" & @CRLF & _ " array(0) {sddsdsd" & @CRLF & _ " }" & @CRLF & _ " ["argc"]=" & @CRLF & _ " int(0)" & @CRLF & _ "}" Local $sSubst = "<i>$1</i><i>$2</i><i>$3</i><i>$4</i>" Local $sResult = StringRegExpReplace($sString, $sRegex, $sSubst) MsgBox($MB_SYSTEMMODAL, "Result", $sResult)

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