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

/
/
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)((((\b(#|\w)+\b\.)?(\bprototype\b\.)?(\b(#|\w)+\b)(\s*\=\s*)?)?(\b(#|\w)+\b\s*)\([\s\w,=]*\s*\))|(\bclass\b\s+\b\w+\b\s*(extends\s*\b\w+\b))(?=\s*\{[\s\S]+\}))(?=\s*\{[\s\S]+\})" Local $sString = "/**" & @CRLF & _ " * Created by jetbrains web development IDE ( Web/PhpStorm )." & @CRLF & _ " * Project: web-component - spineNav" & @CRLF & _ " * User: Pascal Gaudin" & @CRLF & _ " * Mail: pascal.gaudin@zimmerbiomet.com" & @CRLF & _ " * Date: 14/01/2023" & @CRLF & _ " * Time: 14:00" & @CRLF & _ " */" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "/**" & @CRLF & _ " *" & @CRLF & _ " * @type {Window.HTMLElementExtd}" & @CRLF & _ " */" & @CRLF & _ "window.HTMLElementExtd = class HTMLElementExtd extends HTMLElement {" & @CRLF & _ " shadowRoot;" & @CRLF & _ " style;" & @CRLF & _ " elementCustomName;" & @CRLF & _ " /**" & @CRLF & _ " *" & @CRLF & _ " * @param props" & @CRLF & _ " */" & @CRLF & _ " constructor(props) {" & @CRLF & _ " super(props);" & @CRLF & _ " this.shadowRoot = this.attachShadow({mode: 'open'});" & @CRLF & _ " this.host=this.shadowRoot.host;" & @CRLF & _ " this.style= document.createElement('style');" & @CRLF & _ " this.elementCustomName = this.host.tagName.toLowerCase()" & @CRLF & _ " let css = Tools.fetchSync(`web-component/${this.elementCustomName}/default.css`);" & @CRLF & _ " const iJson=new Css(css)" & @CRLF & _ " const jsonCss= iJson.toJson();" & @CRLF & _ " console.log('logg : ', jsonCss);" & @CRLF & _ "" & @CRLF & _ " css += Tools.fetchSync(`web-component/${this.elementCustomName}/custom-element.css`);" & @CRLF & _ "" & @CRLF & _ " this.style.textContent = css;" & @CRLF & _ " this.shadowRoot.appendChild(this.style);" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /**" & @CRLF & _ " *" & @CRLF & _ " * @param objVar" & @CRLF & _ " */" & @CRLF & _ " setVarInCtx(objVar){" & @CRLF & _ " for(name in objVar ) this[name] = objVar[name];" & @CRLF & _ "" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /**" & @CRLF & _ " *" & @CRLF & _ " * @param className" & @CRLF & _ " * @returns {string}" & @CRLF & _ " */" & @CRLF & _ " getStyle(className) {" & @CRLF & _ " var cssText = "";" & @CRLF & _ " var classes = document.styleSheets[0].rules || document.styleSheets[0].cssRules;" & @CRLF & _ " for (var x = 0; x < classes.length; x++) {" & @CRLF & _ " if (classes[x].selectorText == className) {" & @CRLF & _ " cssText += classes[x].cssText || classes[x].style.cssText;" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ " return cssText;" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /**" & @CRLF & _ " *" & @CRLF & _ " * @returns {boolean}" & @CRLF & _ " */" & @CRLF & _ " get firstTime(){" & @CRLF & _ " return this.host.ownerDocument.getElementsByTagName(this.elementCustomName).length===1;" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /**" & @CRLF & _ " *" & @CRLF & _ " * @returns {*[]}" & @CRLF & _ " */" & @CRLF & _ " static get observedAttributes() {" & @CRLF & _ " return [];" & @CRLF & _ " }" & @CRLF & _ " /**" & @CRLF & _ " * document.adoptNode(el)" & @CRLF & _ " */" & @CRLF & _ " adoptedCallback()" & @CRLF & _ " {" & @CRLF & _ " console.log(`Custom-Element ${this.host.nodeName.toLowerCase()} adopt Node !`);" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /**" & @CRLF & _ " * each el.setAttribute" & @CRLF & _ " *" & @CRLF & _ " * @param attrName" & @CRLF & _ " * @param oldVal" & @CRLF & _ " * @param newVal" & @CRLF & _ " */" & @CRLF & _ " attributeChangedCallback(attrName, oldVal, newVal){" & @CRLF & _ " console.log(`Custom-Element ${this.host.nodeName.toLowerCase()} attribute '${attrName}' Changed with value '${newVal}' !`);" & @CRLF & _ "" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /**" & @CRLF & _ " * el.remove()" & @CRLF & _ " *" & @CRLF & _ " */" & @CRLF & _ " disconnectedCallback(){" & @CRLF & _ " console.log(`Custom-Element ${this.host.nodeName.toLowerCase()} Element remove !` );" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /**" & @CRLF & _ " *" & @CRLF & _ " */" & @CRLF & _ " connectedCallback(){" & @CRLF & _ " console.log(`Custom-Element ${this.host.nodeName.toLowerCase()} was inserted in DOM!`);" & @CRLF & _ "" & @CRLF & _ " }" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "/**" & @CRLF & _ " * Created by jetbrains WebStorm ." & @CRLF & _ " * Project: web-component - MyProject" & @CRLF & _ " * User: Pascal Gaudin" & @CRLF & _ " * Mail:" & @CRLF & _ " * Date: 23/01/2023" & @CRLF & _ " * Time: 10:58" & @CRLF & _ " */" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "/**" & @CRLF & _ " *" & @CRLF & _ " * @param attributes" & @CRLF & _ " */" & @CRLF & _ "HTMLElement.prototype.setAttributes=function (attributes) {" & @CRLF & _ " for (const name in attributes) {" & @CRLF & _ " if(name=='textContent') this.textContent= attributes[name];" & @CRLF & _ " if(attributes[name]&&attributes[name]!=='')this.setAttribute(name,attributes[name]);" & @CRLF & _ " if( attributes[name]==='')this.setAttribute(name,'');" & @CRLF & _ " }" & @CRLF & _ "}" & @CRLF & _ "/**" & @CRLF & _ " *" & @CRLF & _ " * @returns {*[]}" & @CRLF & _ " */" & @CRLF & _ "document.createElements =function (){" & @CRLF & _ " const args= [];" & @CRLF & _ " [...arguments].forEach((arg)=>{" & @CRLF & _ " args.push(document.createElement(arg));" & @CRLF & _ " })" & @CRLF & _ " return args;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "/**" & @CRLF & _ " *" & @CRLF & _ " */" & @CRLF & _ "document.toggleFullScreen=function() {" & @CRLF & _ " if (!document.fullscreenElement) {" & @CRLF & _ " document.documentElement.requestFullscreen();" & @CRLF & _ " } else {" & @CRLF & _ " if (document.exitFullscreen) {" & @CRLF & _ " document.exitFullscreen();" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ "}" & @CRLF & _ "/**" & @CRLF & _ " *" & @CRLF & _ " * @returns {*[]}" & @CRLF & _ " */" & @CRLF & _ "HTMLElement.prototype.appendChilds =function ( ) {" & @CRLF & _ " const args= [];" & @CRLF & _ " [...arguments].forEach((arg)=>{" & @CRLF & _ " args.push(this.appendChild(arg));" & @CRLF & _ " })" & @CRLF & _ " return args;" & @CRLF & _ "}" & @CRLF & _ "/**" & @CRLF & _ " *" & @CRLF & _ " * @type {function(): *[]}" & @CRLF & _ " */" & @CRLF & _ "ShadowRoot.prototype.appendChilds= HTMLElement.prototype.appendChilds ;" & @CRLF & _ "" & @CRLF & _ "/**" & @CRLF & _ " *" & @CRLF & _ " * @returns {*[]}" & @CRLF & _ " */" & @CRLF & _ "HTMLElement.prototype.removeChilds=function( ){" & @CRLF & _ " const args= [];" & @CRLF & _ " [...arguments].forEach((arg)=>{" & @CRLF & _ " args.push(this.removeChild(arg));" & @CRLF & _ " })" & @CRLF & _ " return args;" & @CRLF & _ "}" & @CRLF & _ "/**" & @CRLF & _ " *" & @CRLF & _ " * @param txt" & @CRLF & _ " */" & @CRLF & _ "HTMLInputElement.prototype.setFocusBack =function( txt){" & @CRLF & _ "" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "/**" & @CRLF & _ " *" & @CRLF & _ " * @param kill" & @CRLF & _ " */" & @CRLF & _ "HTMLElement.prototype.disconnect=function(kill){" & @CRLF & _ " const numObserved = this.dataset.observed;" & @CRLF & _ " const infoElmt=`of the element '${this.tagName.toLowerCase()}' (with name:'${this.getAttribute('name')??''}')`" & @CRLF & _ " if(this.dataset.hasObserverConnected && this.observer[numObserved] ) {" & @CRLF & _ " this.observer[numObserved].disconnect();" & @CRLF & _ " console.log( `The observer ${infoElmt} n° ${ numObserved } has been disconnected.`);" & @CRLF & _ " if(kill) {" & @CRLF & _ " delete this.observer[numObserved] ;" & @CRLF & _ " console.log( `The observer ${infoElmt} n° ${ numObserved } has been destroy.`);" & @CRLF & _ " }" & @CRLF & _ " delete this.dataset.hasObserverConnected;" & @CRLF & _ " } else {" & @CRLF & _ " console.log( `The observer ${infoElmt} is not connected.`)" & @CRLF & _ " };" & @CRLF & _ "" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "/**" & @CRLF & _ " *" & @CRLF & _ " * @param type" & @CRLF & _ " * @param oldValue" & @CRLF & _ " * @param subtree" & @CRLF & _ " * @param log" & @CRLF & _ " */" & @CRLF & _ "HTMLElement.prototype.observe =function( type,oldValue=true, subtree=true,log=true){" & @CRLF & _ " let numObserved=this.dataset.observed;" & @CRLF & _ " const infoElmt=`of the element '${this.tagName.toLowerCase()}' (with name:'${this.getAttribute('name')??''}')`" & @CRLF & _ " if(arguments && !numObserved) {" & @CRLF & _ " this.config = {...type, subtree};//attributeFilter" & @CRLF & _ " const callback = {}, propertieAllowed = {};" & @CRLF & _ " ['childList', 'attributes', 'characterData'].forEach(_type => {" & @CRLF & _ " this.config[_type] = type.hasOwnProperty(_type);" & @CRLF & _ " callback[_type] = type[_type] ?? undefined;" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ " })" & @CRLF & _ " if (this.config.attributes) this.config.attributeOldValue = oldValue;" & @CRLF & _ " if (this.config.characterData) this.config.characterDataOldValue = oldValue;" & @CRLF & _ "" & @CRLF & _ " propertieAllowed.attributes = ((mut) => { //attributes target newValue attributeName oldValue" & @CRLF & _ " return {" & @CRLF & _ " target : mut.target, newValue: mut.target.getAttribute(mut.attributeName)," & @CRLF & _ " attributeName: mut.attributeName, oldValue: mut.oldValue" & @CRLF & _ " }" & @CRLF & _ " });" & @CRLF & _ " propertieAllowed.childList = ((mut) => {//childList : target addedNodes removedNodes" & @CRLF & _ " return {target: mut.target, addedNodes: [...mut.addedNodes], removedNodes: [...mut.removedNodes]}" & @CRLF & _ " });" & @CRLF & _ " propertieAllowed.characterData = ((mut) => { //characterData oldText newText target" & @CRLF & _ " return {oldText: mut.oldValue, newText: mut.target.data, target: mut.target}" & @CRLF & _ " });" & @CRLF & _ "" & @CRLF & _ " const cbk = (mutationsList) => {" & @CRLF & _ " for (var mutation of mutationsList) {" & @CRLF & _ " if (callback[mutation.type]) callback[mutation.type].call(this, propertieAllowed[mutation.type](mutation));" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ " numObserved= 'obs-'+new Date().getTime();" & @CRLF & _ " this.dataset.observed=numObserved;" & @CRLF & _ "" & @CRLF & _ " this.observer={[numObserved] : new MutationObserver(cbk)};" & @CRLF & _ " if(log)console.log( `The observer ${infoElmt} n° ${ numObserved } is now created.`)" & @CRLF & _ " }" & @CRLF & _ " this.observer[numObserved].observe(this, this.config);" & @CRLF & _ " this.dataset.hasObserverConnected= true;" & @CRLF & _ " if(log)console.log( `The observer ${infoElmt} n° ${ numObserved } is connected.\n\n`)" & @CRLF & _ "" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "/**" & @CRLF & _ " *" & @CRLF & _ " * @param regexs" & @CRLF & _ " * @param strs" & @CRLF & _ " * @param callbacs" & @CRLF & _ " */" & @CRLF & _ "String.prototype.replaceWithArray=function ( regexs, strs,callbacs) {" & @CRLF & _ " let str=this;" & @CRLF & _ " regexs.forEach((regex,idx)=>{" & @CRLF & _ " str = String.prototype.replace.call(str,regex,strs.at(idx),callbacs?.at(idx));" & @CRLF & _ " });" & @CRLF & _ " return str;" & @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