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

/
/
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 = "(%([^:]+):([^%]+)%)" Local $sString = "<!DOCTYPE html>/" & @CRLF & _ "" & @CRLF & _ "<html>" & @CRLF & _ "<head>" & @CRLF & _ "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />" & @CRLF & _ "<title>Testing the checkAndChangeToUrl-Function (Version 5)</title>" & @CRLF & _ "" & @CRLF & _ "<link rel=\"stylesheet\" type=\"text/css\" href=\"[__protocol__]://[__server__]:[__port__]/weblis-ext3/ext/resources/css/ext-all.css\" />" & @CRLF & _ "<script type=\"text/javascript\" src=\"[__protocol__]://[__server__]:[__port__]/weblis-ext3/ext/adapter/ext/ext-base-debug.js\"></script>" & @CRLF & _ "<script type=\"text/javascript\" src=\"[__protocol__]://[__server__]:[__port__]/weblis-ext3/ext/ext-all-debug.js\"></script>" & @CRLF & _ "<script type=\"text/javascript\" src=\"[__protocol__]://[__server__]:[__port__]/weblis-ext3/ext/locale/ext-lang-de.js\"></script>" & @CRLF & _ "" & @CRLF & _ "<script type=\"text/javascript\" src=\"[__protocol__]://[__server__]:[__port__]/weblis-resources/js/jquery/jquery-3.2.1.js\"></script>" & @CRLF & _ "" & @CRLF & _ "<script type=\"text/javascript\">" & @CRLF & _ "" & @CRLF & _ "function checkAndChangeToUrl(url, maxRetries, waitTime, waitFunc, startFunc, successFunc, errorFunc) {" & @CRLF & _ "console.log(\"ENTER checkAndChangeToUrl('\"+url+\"', \"+maxRetries+\", \"+waitTime+\")\");" & @CRLF & _ "var nRetry = 0;" & @CRLF & _ "var checkUrl = function () {" & @CRLF & _ "$.ajax({" & @CRLF & _ "url: url," & @CRLF & _ "context: document.body," & @CRLF & _ "crossDomain: true," & @CRLF & _ "error: function(jqXHR, textStatus, errorThrown) {" & @CRLF & _ "console.error(textStatus + \";" & @CRLF & _ "\" + errorThrown);" & @CRLF & _ "nRetry++;" & @CRLF & _ "if (nRetry <= maxRetries) {" & @CRLF & _ "waitFunc.call(jqXHR, jqXHR);" & @CRLF & _ "console.log(\"Retry #\" + nRetry);" & @CRLF & _ "var timeout = (nRetry == 0 ? 0 : waitTime);" & @CRLF & _ "console.log(\"timeout = \" + timeout);" & @CRLF & _ "setTimeout(checkUrl, timeout);" & @CRLF & _ "if (nRetry === 1) {" & @CRLF & _ "console.log(\"**** Try and open the target application ****\");" & @CRLF & _ "// PROBLEM: parent[.parent].handleExternalEvent() existiert nicht..." & @CRLF & _ "startFunc.call(jqXHR, jqXHR);" & @CRLF & _ "}" & @CRLF & _ "} else {" & @CRLF & _ "errorFunc.call(jqXHR, jqXHR);" & @CRLF & _ "}" & @CRLF & _ "return;" & @CRLF & _ "}," & @CRLF & _ "success : function(data, textStatus, jqXHR) {" & @CRLF & _ "console.log(\"Success!\");" & @CRLF & _ "successFunc.call(jqXHR, jqXHR);" & @CRLF & _ "}" & @CRLF & _ "}).done(function() {" & @CRLF & _ "$( this ).addClass( \"done\" );" & @CRLF & _ "console.log(\"Done!\");" & @CRLF & _ "});" & @CRLF & _ "};" & @CRLF & _ "// Wir setzen das Ganze in Gang..." & @CRLF & _ "checkUrl();" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "function test_1(checkUrl, targetUrl, launchUrl) {" & @CRLF & _ "//var url = \"%param:checkUrl%\"; " & @CRLF & _ "//var url = \"http://localhost:8080/RechercheServlet/rest/forcont/fxLIS?DOKID=1&VID=1&OP=RECEIVE\"; " & @CRLF & _ "//var url = \"http://localhost:8085/gn\";" & @CRLF & _ "console.log(\"VOR checkAndChangeToUrl('\"+checkUrl+\"', 2, 5000) ...\");" & @CRLF & _ "var ret = checkAndChangeToUrl(checkUrl, 2, 2000, function(jqXHR) {" & @CRLF & _ "console.log(\"Waiting...\");" & @CRLF & _ "}, function(jqXHR) {" & @CRLF & _ "console.log(\"Start application...\");" & @CRLF & _ "$.ajax({" & @CRLF & _ "url: %param:launchUrl%, //\"/opusp-rest/client-action/execute/local/GIS_Launch\"," & @CRLF & _ "context: document.body," & @CRLF & _ "crossDomain: false, //true, -- SYNCHRONER AUFRUF - SCHWERE SÜNDE..." & @CRLF & _ "headers: {" & @CRLF & _ "'Accept' : 'application/x-java-jnlp-file', /* application/jnlp */" & @CRLF & _ "'Content-Description' : 'File Transfer'," & @CRLF & _ "'Content-Disposition' : 'attachment; filename=GIS_Launch.jnlp'" & @CRLF & _ "}," & @CRLF & _ "error: function(jqXHR, textStatus, errorThrown) {" & @CRLF & _ "console.error(\"Fehler bei Aktion GIS_Launch:" & @CRLF & _ "\" + textStatus + \";" & @CRLF & _ "\" + errorThrown);" & @CRLF & _ "return;" & @CRLF & _ "}," & @CRLF & _ "success : function(data, textStatus, jqXHR) {" & @CRLF & _ "console.log(\"GIS_Launch: Success! JNLP = '\" + data + \"'\");" & @CRLF & _ "}" & @CRLF & _ "}).done(function() {" & @CRLF & _ "$( this ).addClass( \"done\" );" & @CRLF & _ "console.log(\"GIS_Launch: Done!\");" & @CRLF & _ "});" & @CRLF & _ "}, function(jqXHR) {" & @CRLF & _ "console.log(\"Success.\");" & @CRLF & _ "window.location.href = targetUrl;" & @CRLF & _ "}, function(jqXHR) {" & @CRLF & _ "console.log(\"Error: \" + jqXHR.statusText + \", jqXHR.state() = \" + jqXHR.state());" & @CRLF & _ "});" & @CRLF & _ "console.log(\"LEAVE test_1.\");" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "function performTest_1() {" & @CRLF & _ "test_1(" & @CRLF & _ "\"[__checkUrl__]\", // Parameter: checkUrl, z.B. \"http://localhost:8080/RechercheServlet\" " & @CRLF & _ "\"%param:targetUrl%\", // Parameter: targetUrl, z.B. \"http://localhost:8080/RechercheServlet/rest/forcont/fxLIS?DOKID=1&VID=1&OP=RECEIVE\"" & @CRLF & _ "\"[__launchUrl__]\" // Parameter: launchUrl, z.B. \"/opusp-rest/client-action/execute/local/GIS_Launch\"" & @CRLF & _ ")" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "$.when($.ready).then(function() {" & @CRLF & _ "performTest_1();" & @CRLF & _ "});" & @CRLF & _ "" & @CRLF & _ "</script>" & @CRLF & _ "</head>" & @CRLF & _ "<body>" & @CRLF & _ "<a id=\"test_1\" onclick=\"performTest_1();\"><button type=\"button\">Perform Test #1</button></a>" & @CRLF & _ "</body>" & @CRLF & _ "</html>" & @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