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 = "(\/)(\*)(.|\n)*?\2\1|(\/\/.*)" Local $sString = "#include<stdio.h>" & @CRLF & _ "#include<stdlib.h>" & @CRLF & _ "typedef struct Node" & @CRLF & _ "{" & @CRLF & _ " int data;" & @CRLF & _ " struct Node *next;" & @CRLF & _ " struct Node *prev;" & @CRLF & _ "}node;" & @CRLF & _ "void insert(node *pointer, int data)" & @CRLF & _ "{" & @CRLF & _ " /* Iterate through the list till we encounter the last node.*/" & @CRLF & _ " while(pointer->next!=NULL)" & @CRLF & _ " {" & @CRLF & _ " pointer = pointer -> next;" & @CRLF & _ " }" & @CRLF & _ " /* Allocate memory for the new node and put data in it.*/" & @CRLF & _ " pointer->next = (node *)malloc(sizeof(node));" & @CRLF & _ " (pointer->next)->prev = pointer;" & @CRLF & _ " pointer = pointer->next;" & @CRLF & _ " pointer->data = data;" & @CRLF & _ " pointer->next = NULL;" & @CRLF & _ "}" & @CRLF & _ "int find(node *pointer, int key)" & @CRLF & _ "{" & @CRLF & _ " pointer = pointer -> next; //First node is dummy node." & @CRLF & _ " /* Iterate through the entire linked list and search for the key. */" & @CRLF & _ " while(pointer!=NULL)" & @CRLF & _ " {" & @CRLF & _ " if(pointer->data == key) //key is found." & @CRLF & _ " {" & @CRLF & _ " return 1;" & @CRLF & _ " }" & @CRLF & _ " pointer = pointer -> next;//Search in the next node." & @CRLF & _ " }" & @CRLF & _ " /*Key is not found */" & @CRLF & _ " return 0;" & @CRLF & _ "}" & @CRLF & _ "void delete(node *pointer, int data)" & @CRLF & _ "{" & @CRLF & _ " /* Go to the node for which the node next to it has to be deleted */" & @CRLF & _ " while(pointer->next!=NULL && (pointer->next)->data != data)" & @CRLF & _ " {" & @CRLF & _ " pointer = pointer -> next;" & @CRLF & _ " }" & @CRLF & _ " if(pointer->next==NULL)" & @CRLF & _ " {" & @CRLF & _ " printf("Element %d is not present in the list\n",data);" & @CRLF & _ " return;" & @CRLF & _ " }" & @CRLF & _ " /* Now pointer points to a node and the node next to it has to be removed */" & @CRLF & _ " node *temp;" & @CRLF & _ " temp = pointer -> next;" & @CRLF & _ " /*temp points to the node which has to be removed*/" & @CRLF & _ " pointer->next = temp->next;" & @CRLF & _ " temp->prev = pointer;" & @CRLF & _ " /*We removed the node which is next to the pointer (which is also temp) */" & @CRLF & _ " free(temp);" & @CRLF & _ " /* Beacuse we deleted the node, we no longer require the memory used for it ." & @CRLF & _ " free() will deallocate the memory." & @CRLF & _ " */" & @CRLF & _ " return;" & @CRLF & _ "}" & @CRLF & _ "void print(node *pointer)" & @CRLF & _ "{" & @CRLF & _ " if(pointer==NULL)" & @CRLF & _ " {" & @CRLF & _ " return;" & @CRLF & _ " }" & @CRLF & _ " printf("%d ",pointer->data);" & @CRLF & _ " print(pointer->next);" & @CRLF & _ "}" & @CRLF & _ "int main()" & @CRLF & _ "{" & @CRLF & _ " /* start always points to the first node of the linked list." & @CRLF & _ " temp is used to point to the last node of the linked list.*/" & @CRLF & _ " node *start,*temp;" & @CRLF & _ " start = (node *)malloc(sizeof(node));" & @CRLF & _ " temp = start;" & @CRLF & _ " temp -> next = NULL;" & @CRLF & _ " temp -> prev = NULL;" & @CRLF & _ " /* Here in this code, we take the first node as a dummy node." & @CRLF & _ " The first node does not contain data, but it used because to avoid handling special cases" & @CRLF & _ " in insert and delete functions." & @CRLF & _ " */" & @CRLF & _ " printf("1. Insert\n");" & @CRLF & _ " printf("2. Delete\n");" & @CRLF & _ " printf("3. Print\n");" & @CRLF & _ " printf("4. Find\n");" & @CRLF & _ " while(1)" & @CRLF & _ " {" & @CRLF & _ " int query;" & @CRLF & _ " scanf("%d",&query);" & @CRLF & _ " if(query==1)" & @CRLF & _ " {" & @CRLF & _ " int data;" & @CRLF & _ " scanf("%d",&data);" & @CRLF & _ " insert(start,data);" & @CRLF & _ " }" & @CRLF & _ " else if(query==2)" & @CRLF & _ " {" & @CRLF & _ " int data;" & @CRLF & _ " scanf("%d",&data);" & @CRLF & _ " delete(start,data);" & @CRLF & _ " }" & @CRLF & _ " else if(query==3)" & @CRLF & _ " {" & @CRLF & _ " printf("The list is ");" & @CRLF & _ " print(start->next);" & @CRLF & _ " printf("\n");" & @CRLF & _ " }" & @CRLF & _ " else if(query==4)" & @CRLF & _ " {" & @CRLF & _ " int data;" & @CRLF & _ " scanf("%d",&data);" & @CRLF & _ " int status = find(start,data);" & @CRLF & _ " if(status)" & @CRLF & _ " {" & @CRLF & _ " printf("Element Found\n");" & @CRLF & _ " }" & @CRLF & _ " else" & @CRLF & _ " {" & @CRLF & _ " printf("Element Not Found\n");" & @CRLF & _ "" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ " }" & @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