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

/
/
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)(?i)(?:\w+\W+){0,9}?(?=.*(?:plot).*|.*(?:over).*)(?:\w+\W+){0,9}?(?=Charlie|Muir|Charlie Muir)\K(?:(?:Charlie|Muir|Charlie Muir)\s+)+" Local $sString = "POSITIVE TESTING" & @CRLF & _ "" & @CRLF & _ "1." & @CRLF & _ "Charlie Muir was over the moon." & @CRLF & _ "next next next next next next next next next next next next next next " & @CRLF & _ "Charlie Muir was in the plot ." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "" & @CRLF & _ "2." & @CRLF & _ "Charlie was over the moon." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "Charlie was in the plot ." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "" & @CRLF & _ "3." & @CRLF & _ "Mr. Charlie was over the moon." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "Mr.Muir was in the plot." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "" & @CRLF & _ "4." & @CRLF & _ "When Charlie saw the letter , Charlie was over the moon." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "When Charlie saw the letter, ChaRLIE was walking in the plot." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "" & @CRLF & _ "5." & @CRLF & _ "When Charlie Muir saw letter , Charlie Muir was over the moon." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "When Charlie Muir saw letter, ChaRLIE MUIR was walking in plot." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "" & @CRLF & _ "6." & @CRLF & _ "When Muir saw letter , Mr.Muir was over the moon." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "When Mr.MUIR saw letter, Mr.CharliE was walking in plot." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "" & @CRLF & _ "7." & @CRLF & _ "When Muir saw letter , Mr.Charlie Muir was over the moon." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "When Mr.Charlie saw letter, Mr.MUIR was walking in plot." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "" & @CRLF & _ "8." & @CRLF & _ "Charlie Muir was Over the moon." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "Charlie Muir was in the PLOT ." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "" & @CRLF & _ "9." & @CRLF & _ "He,Charlie and Muir were OVEr the moon." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "Charlie and MR.MUIR were in the ploT ." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "" & @CRLF & _ "10." & @CRLF & _ "Over the moon was Charlie." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "Plot was far away from Charlie." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "" & @CRLF & _ "11." & @CRLF & _ "OVER the moon was Charlie Muir." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "Plot was far away from CHARLIE MUIR." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "" & @CRLF & _ "12." & @CRLF & _ "over the moon were Charlie and Muir." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "Plot was far away from Charlie and Muir." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "" & @CRLF & _ "13." & @CRLF & _ "Over the moon was Mr.Muir whose first name is Charlie." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "PLOT was far away from Charlie whose last name is MUIR." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "" & @CRLF & _ "14." & @CRLF & _ "OVER the moon was MUIR who is also charlie Muir." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "plot was far away from MUIR who is also CHarlie Muir." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "" & @CRLF & _ "---------------------------------------------------------------------" & @CRLF & _ "" & @CRLF & _ "POSITVE / NEGATIVE TESTING" & @CRLF & _ "" & @CRLF & _ "15." & @CRLF & _ "Charlie knew when CHARLIE saw the letter that he would be over the moon after reading it." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "Charlie knew what the letter would contain when Charlie was reading it while walking in the plot." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "" & @CRLF & _ "16." & @CRLF & _ "Charlie knew when Charlie and muir saw the letter that they would be over the moon" & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "Charlie knew when Charlie and Muir saw the letter that they would be in the plot" & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "" & @CRLF & _ "17." & @CRLF & _ "Charlie knew when Charlie Muir saw the letter that they would be over the moon" & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "Charlie knew when Charlie Muir saw the letter that they would be in the plot" & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "" & @CRLF & _ "18." & @CRLF & _ "over the moon was Charlie Muir who is also known simply as CHARLIE." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "The plot was far away from Charlie Muir who is also known simply as CHARLIE." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "" & @CRLF & _ "19." & @CRLF & _ "OVER the moon was Mr.ChaRlie and Muir who are together known as the MuIr Brothers." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "The plot was far away from Charlie and Muir who are together known as the MUIR Brothers." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "-----------------------------------------------------------------------" & @CRLF & _ "" & @CRLF & _ "NEGATIVE TESTING" & @CRLF & _ "" & @CRLF & _ "20." & @CRLF & _ "Charlie Muir , after receiving and reading letter was addressed to him , was over the moon." & @CRLF & _ "next next next next next next next next next next next next next next" & @CRLF & _ "Charlie Muir received and read the letter was addressed to him in plot." & @CRLF & _ "next next next next next next next next next next next next next next" & @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