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
No Match

/
/
mg

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)(var preferences = {)[\s\S]*(};)" Local $sString = "<!DOCTYPE html>" & @CRLF & _ "<html>" & @CRLF & _ " <head>" & @CRLF & _ " <meta http-equiv='x-ua-compatible' content='IE=edge,chrome=1' />" & @CRLF & _ " <meta name="robots" content="nofollow" />" & @CRLF & _ " <meta name="robots" content="noindex" />" & @CRLF & _ " <meta name="robots" content="noarchive" />" & @CRLF & _ " <meta http-equiv="Cache-Control" content="private, no-cache, no-store, must-revalidate, max-age=0" />" & @CRLF & _ " <meta http-equiv="Pragma" content="no-cache" />" & @CRLF & _ " <meta http-equiv="Expires" content="0" />" & @CRLF & _ " <meta http-equiv="Expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />" & @CRLF & _ " <meta charset='UTF-8' />" & @CRLF & _ " <title>BLANK - FILL WITH CLIENT TITLE</title>" & @CRLF & _ " <link href='css/bpdev.css' rel='stylesheet' type='text/css' />" & @CRLF & _ " <script src='https://code.jquery.com/jquery-1.11.1.min.js'></script>" & @CRLF & _ " <script>!window.jQuery && document.write('<script src="common/js/jquery/jquery-1.11.1.min.js"><\/script>');</script>" & @CRLF & _ " <link rel='shortcut icon' href='images/favicon.ico' type='image/x-icon' />" & @CRLF & _ " <style id="antiClickjack">body{display:none !important;}</style>" & @CRLF & _ " </head>" & @CRLF & _ " <body id='userTools'>" & @CRLF & _ " <div id='notificationContainer' data-automation='notification_window'></div>" & @CRLF & _ " <div id='overlay' class='modalOverlay' data-automation='modal_overlay'></div>" & @CRLF & _ " <div id='dialog' class='modal' data-automation='modal_window'></div>" & @CRLF & _ " <div id='container'>" & @CRLF & _ " <div id='header' data-automation='header'></div>" & @CRLF & _ " <div id='loader' data-automation='content_loader'></div>" & @CRLF & _ " <div id='content' data-automation='content_area'></div>" & @CRLF & _ " </div>" & @CRLF & _ " <div id='copyFooter' class='copyright' data-automation='copyright_footer'></div>" & @CRLF & _ " <script src='common/js/gateway.framework-min.js' type='text/javascript'></script>" & @CRLF & _ " <script src='common/js/gateway.app-min.js' type='text/javascript'></script>" & @CRLF & _ " <script type='text/javascript'>" & @CRLF & _ " if (self === top) {" & @CRLF & _ " var antiClickjack = document.getElementById('antiClickjack');" & @CRLF & _ " antiClickjack.parentNode.removeChild(antiClickjack);" & @CRLF & _ " } else {" & @CRLF & _ " top.location = self.location;" & @CRLF & _ " }" & @CRLF & _ " (function($) {" & @CRLF & _ " var preferences = {" & @CRLF & _ " logo : 'images/logo.png'," & @CRLF & _ " logoWidth : 250," & @CRLF & _ " logoHeight : 38," & @CRLF & _ " logoAlt : ''," & @CRLF & _ " logoLink : ''," & @CRLF & _ " logoutURL : '../../pkmslogout'" & @CRLF & _ " };" & @CRLF & _ " Gateway.startGateway(preferences, true);" & @CRLF & _ " }(jQuery));" & @CRLF & _ " </script>" & @CRLF & _ " </body>" & @CRLF & _ "</html>" 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