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

/
/
gs

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 = "(?s){.+|(?<=var)\s+([^\s]+)\s*=\s*['"]([^'"]+?)['"];" Local $sString = "//stuff" & @CRLF & _ "var RootJsURL = "/trunk/js/portal"; //The root of the OpenMap Application" & @CRLF & _ "var RootRestUrl = "/trunk/rest"; //root of the restful services directory" & @CRLF & _ "var stripePublicKey = 'pk_test_rAYTGcpiFtrXvXpYic4C0Mt0';//the public key for your stripe account" & @CRLF & _ "" & @CRLF & _ "//global functions for any tool to use" & @CRLF & _ "var showErrorPopup = function(title, message) {" & @CRLF & _ " Ext.MessageBox.show({" & @CRLF & _ " title: title," & @CRLF & _ " msg: "Error: " + message," & @CRLF & _ " buttons: Ext.MessageBox.OK," & @CRLF & _ " icon: Ext.Msg.ERROR" & @CRLF & _ " });" & @CRLF & _ "};" & @CRLF & _ "" & @CRLF & _ "/**" & @CRLF & _ " * checks if there is an error, if so display it" & @CRLF & _ " * @param obj the response json to check for an error" & @CRLF & _ " * @param title the title of the error pop up box" & @CRLF & _ " * @returns {boolean} true if there is an error, false otherwise" & @CRLF & _ " */" & @CRLF & _ "var checkResponseForError = function(obj, title) {" & @CRLF & _ " if (obj.error) {" & @CRLF & _ " if (obj.loggedIn) {" & @CRLF & _ " showErrorPopup(title, obj.error);" & @CRLF & _ " return true;" & @CRLF & _ " }" & @CRLF & _ " else {" & @CRLF & _ " countdown.modal.show();" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ " return false;" & @CRLF & _ "};" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "//The configure object that puts it all together" & @CRLF & _ "var Configure = {" & @CRLF & _ " LBAR:[]," & @CRLF & _ " TBAR:[]," & @CRLF & _ " BBAR:[]," & @CRLF & _ " RBAR:[]," & @CRLF & _ " centerbar:null," & @CRLF & _ " /**" & @CRLF & _ " * List of window resize functions" & @CRLF & _ " */" & @CRLF & _ " ResizeEvents:[]," & @CRLF & _ " /**" & @CRLF & _ " * Gets the working size of the main panel" & @CRLF & _ " * @returns {number}" & @CRLF & _ " */" & @CRLF & _ " GetClientHeight:function(){" & @CRLF & _ " //var body = document.body;" & @CRLF & _ " //var html = document.documentElement;" & @CRLF & _ " var bannerHeight = document.getElementById("bannerimg").height;" & @CRLF & _ " //return Math.max(body.scrollHeight, body.offsetHeight,html.clientHeight, html.scrollHeight, html.offsetHeight)-bannerHeight-5;//Buffer of 5px --> need to fix and make it universal" & @CRLF & _ " return Ext.getBody().getViewSize().height -bannerHeight-5;" & @CRLF & _ " }," & @CRLF & _ " /**" & @CRLF & _ " * Configure all global variables" & @CRLF & _ " */" & @CRLF & _ " Globals:function(){" & @CRLF & _ " //Create the dynamic content panel" & @CRLF & _ " this.centerbar = Ext.create('Ext.panel.Panel',{" & @CRLF & _ " region:'center'," & @CRLF & _ " autoScroll:true" & @CRLF & _ " });" & @CRLF & _ " }," & @CRLF & _ " /**" & @CRLF & _ " * Assembles all tools into the main panel before drawing" & @CRLF & _ " */" & @CRLF & _ " MainPanel:function(){" & @CRLF & _ " " & @CRLF & _ " //If LBar and BBar are empty, don't bother rendering them --> set to null" & @CRLF & _ " var topArray = [];" & @CRLF & _ " var bottomArray = []; " & @CRLF & _ " " & @CRLF & _ " if(this.TBAR.length >0){" & @CRLF & _ " topArray = topArray.concat(this.TBAR);" & @CRLF & _ " }" & @CRLF & _ " if(this.BBAR.length >0){" & @CRLF & _ " bottomArray = bottomArray.concat(this.BBAR);" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " //Top bar --> Persistant tools" & @CRLF & _ " var TopBar = Ext.create('Ext.panel.Panel',{" & @CRLF & _ " region: 'north'," & @CRLF & _ " width:'100%'," & @CRLF & _ " layout:{" & @CRLF & _ " type:'hbox'," & @CRLF & _ " align: 'left'," & @CRLF & _ " pack: 'end'" & @CRLF & _ " }," & @CRLF & _ " margin: '0 0 0 0'," & @CRLF & _ " items: topArray" & @CRLF & _ " });" & @CRLF & _ " //Bottom bar --> usually pertinant info" & @CRLF & _ " var BottomBar = Ext.create('Ext.panel.Panel',{" & @CRLF & _ " region: 'south'," & @CRLF & _ " width:'100%'," & @CRLF & _ " layout:'hbox'," & @CRLF & _ " margin: '0 0 0 0'," & @CRLF & _ " items: bottomArray" & @CRLF & _ " });" & @CRLF & _ " " & @CRLF & _ " //Side tool panel --> Extensible tools" & @CRLF & _ " var toolbar = Ext.create('Ext.panel.Panel',{" & @CRLF & _ " region: 'west'," & @CRLF & _ " width: 200," & @CRLF & _ " minWidth: 200," & @CRLF & _ " maxWidth: 400," & @CRLF & _ " collapsible: false," & @CRLF & _ " animCollapse:true," & @CRLF & _ " hideCollapseTool: true," & @CRLF & _ " floatable: true," & @CRLF & _ " split: false," & @CRLF & _ " margin: '0 0 0 0', " & @CRLF & _ " layout:{" & @CRLF & _ " type: 'vbox'" & @CRLF & _ " }," & @CRLF & _ " items:this.LBAR" & @CRLF & _ " });" & @CRLF & _ " " & @CRLF & _ " //Right tool panel --> Extensible tools" & @CRLF & _ " var Rightbar = Ext.create('Ext.panel.Panel',{" & @CRLF & _ " region: 'east'," & @CRLF & _ " title:'Portal Information'," & @CRLF & _ " width: 200," & @CRLF & _ " minWidth: 200," & @CRLF & _ " maxWidth: 400," & @CRLF & _ " collapsible: true," & @CRLF & _ " animCollapse:true," & @CRLF & _ " hideCollapseTool: true," & @CRLF & _ " floatable: true," & @CRLF & _ " split: false," & @CRLF & _ " margin: '0 0 0 0', " & @CRLF & _ " layout:{" & @CRLF & _ " type: 'fit'" & @CRLF & _ " }," & @CRLF & _ " items:this.RBAR" & @CRLF & _ " });" & @CRLF & _ " if(!Rightbar.getCollapsed()){" & @CRLF & _ " Rightbar.toggleCollapse(); " & @CRLF & _ " } " & @CRLF & _ " " & @CRLF & _ " var cb = this.centerbar;" & @CRLF & _ "" & @CRLF & _ " //Overall Panel --> Contains everything" & @CRLF & _ " MainPanel = Ext.create('Ext.panel.Panel',{" & @CRLF & _ " layout: {" & @CRLF & _ " type:'border'," & @CRLF & _ " padding: '0 0 0 0'," & @CRLF & _ " margin: '0 0 0 0'" & @CRLF & _ " }," & @CRLF & _ " width: '100%'," & @CRLF & _ " height:Configure.GetClientHeight(),//Buffer of 3px --> need to fix and make it universal" & @CRLF & _ " items:[toolbar,cb,TopBar,BottomBar,Rightbar]," & @CRLF & _ " renderTo: Ext.getBody()" & @CRLF & _ " }); " & @CRLF & _ "" & @CRLF & _ " //Window resize event" & @CRLF & _ " Ext.EventManager.onWindowResize(function () {" & @CRLF & _ " var width = '100%';" & @CRLF & _ " var height = Configure.GetClientHeight();" & @CRLF & _ "" & @CRLF & _ " MainPanel.setSize(width, height);" & @CRLF & _ " for(var i = 0; i< Configure.ResizeEvents.length;i++){" & @CRLF & _ " Configure.ResizeEvents[i]();" & @CRLF & _ " }" & @CRLF & _ " });" & @CRLF & _ " }," & @CRLF & _ "" & @CRLF & _ " /**" & @CRLF & _ " * Adds an element to the left hand side of the page" & @CRLF & _ " * @param {Array} elements" & @CRLF & _ " * @return void " & @CRLF & _ " */" & @CRLF & _ " AddToLeftbar:function(elements){" & @CRLF & _ " this.LBAR = this.LBAR.concat(elements);" & @CRLF & _ " }," & @CRLF & _ " /**" & @CRLF & _ " * Adds an element to the top of the page" & @CRLF & _ " * @param {Array} elements" & @CRLF & _ " * @return void " & @CRLF & _ " */" & @CRLF & _ " AddToTopbar:function(elements){" & @CRLF & _ " this.TBAR = this.TBAR.concat(elements);" & @CRLF & _ " }," & @CRLF & _ " /**" & @CRLF & _ " * Adds an element to the bottom of the page" & @CRLF & _ " * @param {Array} elements" & @CRLF & _ " * @return void " & @CRLF & _ " */" & @CRLF & _ " AddToBottombar:function(elements){" & @CRLF & _ " this.BBAR = this.BBAR.concat(elements);" & @CRLF & _ " }," & @CRLF & _ " /**" & @CRLF & _ " * Adds an element to the right hand side of the page" & @CRLF & _ " * @params {Array} elements" & @CRLF & _ " * @return void " & @CRLF & _ " */" & @CRLF & _ " AddToRightbar:function(elements){" & @CRLF & _ " this.RBAR = this.RBAR.concat(elements);" & @CRLF & _ " }," & @CRLF & _ " /**" & @CRLF & _ " * Replaces the center panel content" & @CRLF & _ " * @params {Ext.Component} element" & @CRLF & _ " * @return void " & @CRLF & _ " */" & @CRLF & _ " UpdateContent:function(element){" & @CRLF & _ " WindowManager.Clear();" & @CRLF & _ " this.centerbar.removeAll(false);" & @CRLF & _ " this.centerbar.add(element);" & @CRLF & _ " }," & @CRLF & _ " /**" & @CRLF & _ " * Adds a window resize event" & @CRLF & _ " * @params {function} func" & @CRLF & _ " * @return void " & @CRLF & _ " */" & @CRLF & _ " AddResizeEvent:function(func){" & @CRLF & _ " this.ResizeEvents = this.ResizeEvents.concat(func);" & @CRLF & _ " }" & @CRLF & _ "}" & @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