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)<div[\s\S]*?id=\"variationsTwister[\s\S]*?<span[\s\S]*?a-dropdown-container[\s\S]*?<select[\s\S]*?<\/select>[\s\S]*?Color:<\/span>[\s\S]*?<span[\s\S]*?>([\s\S]*?)<\/span>" Local $sString = "<div id="variationsTwister" class="a-section a-spacing-mini">" & @CRLF & _ " " & @CRLF & _ "" & @CRLF & _ " " & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ "" & @CRLF & _ " <div class="a-section a-spacing-micro">" & @CRLF & _ " <span class="a-size-base">Size:</span>" & @CRLF & _ " <span class="a-size-base a-text-bold"></span>" & @CRLF & _ " </div>" & @CRLF & _ " <span class="a-dropdown-container"><select name="" autocomplete="off" data-a-native-class="olpTwisterDropdown" tabindex="-1" class="a-native-dropdown a-spacing-small olpTwisterDropdown">" & @CRLF & _ " <option value="/gp/offer-listing/B00NNA39IE/ref=olp_twister_all?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=all">" & @CRLF & _ " Lowest offer for each" & @CRLF & _ " </option>" & @CRLF & _ " <option value="/gp/offer-listing/B00MC3QSKO/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=0">" & @CRLF & _ " 5 M US" & @CRLF & _ " </option>" & @CRLF & _ " <option value="/gp/offer-listing/B00MC3QU1G/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=1">" & @CRLF & _ " 5.5 M US" & @CRLF & _ " </option>" & @CRLF & _ " <option value="/gp/offer-listing/B00MC3QX72/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=2">" & @CRLF & _ " 6 M US" & @CRLF & _ " </option>" & @CRLF & _ " <option value="/gp/offer-listing/B00MC3QYQC/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=3">" & @CRLF & _ " 6.5 M US" & @CRLF & _ " </option>" & @CRLF & _ " <option value="/gp/offer-listing/B00MC3R0PQ/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=4">" & @CRLF & _ " 7 M US" & @CRLF & _ " </option>" & @CRLF & _ " <option value="/gp/offer-listing/B00MC3R23Q/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=5">" & @CRLF & _ " 7.5 M US" & @CRLF & _ " </option>" & @CRLF & _ " <option value="/gp/offer-listing/B00MC3R3M6/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=6" selected="">" & @CRLF & _ " 8 M US" & @CRLF & _ " </option>" & @CRLF & _ " <option value="/gp/offer-listing/B00MC3R6LO/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=7">" & @CRLF & _ " 8.5 M US" & @CRLF & _ " </option>" & @CRLF & _ " <option value="/gp/offer-listing/B00MC3R9IY/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=8">" & @CRLF & _ " 9 M US" & @CRLF & _ " </option>" & @CRLF & _ " <option value="/gp/offer-listing/B00MC3RBE6/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=9">" & @CRLF & _ " 9.5 M US" & @CRLF & _ " </option>" & @CRLF & _ " <option value="/gp/offer-listing/B00MC3RCPY/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=10">" & @CRLF & _ " 10 M US" & @CRLF & _ " </option>" & @CRLF & _ " </select><span tabindex="-1" id="olpTwisterDropdownAUI" class="a-button a-button-dropdown a-button-small a-spacing-small" style="min-width: 0.583333%;"><span class="a-button-inner"><span class="a-button-text a-declarative" data-action="a-dropdown-button" role="button" tabindex="0" aria-hidden="true"><span class="a-dropdown-prompt">" & @CRLF & _ " 8 M US" & @CRLF & _ " </span></span><i class="a-icon a-icon-dropdown"></i></span></span></span>" & @CRLF & _ " <div class="a-section a-spacing-micro">" & @CRLF & _ " <span class="a-size-base">Color:</span>" & @CRLF & _ " <span class="a-size-base a-text-bold">Taupe</span>" & @CRLF & _ " </div>" & @CRLF & _ " <ul class="a-unordered-list a-nostyle a-button-list a-declarative a-button-toggle-group a-horizontal a-spacing-small" role="radiogroup" data-action="a-button-group">" & @CRLF & _ " <li class="a-spacing-mini"><span class="a-list-item">" & @CRLF & _ " <span class="a-button a-button-normal a-button-thumbnail a-button-toggle" id="a-autoid-0"><span class="a-button-inner"><a href="/gp/offer-listing/B0002MB0DM/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=0&amp;mv_size_name=6" class="a-button-text" role="button" id="a-autoid-0-announce">" & @CRLF & _ " <img alt="" src="https://images-na.ssl-images-amazon.com/images/I/41jl1EwZjHL._SX35_SY35_CR,0,0,35,35_.jpg" height="35" width="35">" & @CRLF & _ " </a></span></span>" & @CRLF & _ " </span></li>" & @CRLF & _ " <li class="a-spacing-mini"><span class="a-list-item">" & @CRLF & _ " <span class="a-button a-button-normal a-button-thumbnail a-button-toggle" id="a-autoid-1"><span class="a-button-inner"><a href="/gp/offer-listing/B005BFV1DO/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=1&amp;mv_size_name=6" class="a-button-text" role="button" id="a-autoid-1-announce">" & @CRLF & _ " <img alt="" src="https://images-na.ssl-images-amazon.com/images/I/41XqEgaqwtL._SX35_SY35_CR,0,0,35,35_.jpg" height="35" width="35">" & @CRLF & _ " </a></span></span>" & @CRLF & _ " </span></li>" & @CRLF & _ " <li class="a-spacing-mini"><span class="a-list-item">" & @CRLF & _ " <span class="a-button a-button-normal a-button-thumbnail a-button-toggle" id="a-autoid-2"><span class="a-button-inner"><a href="/gp/offer-listing/B00MC3SFXW/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=2&amp;mv_size_name=6" class="a-button-text" role="button" id="a-autoid-2-announce">" & @CRLF & _ " <img alt="" src="https://images-na.ssl-images-amazon.com/images/I/41cNhnckTFL._SX35_SY35_CR,0,0,35,35_.jpg" height="35" width="35">" & @CRLF & _ " </a></span></span>" & @CRLF & _ " </span></li>" & @CRLF & _ " <li class="a-spacing-mini"><span class="a-list-item">" & @CRLF & _ " <span class="a-button a-button-selected a-button-thumbnail a-button-toggle" id="a-autoid-3"><span class="a-button-inner"><a href="/gp/offer-listing/B00MC3R3M6/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=6" class="a-button-text" role="button" id="a-autoid-3-announce">" & @CRLF & _ " <img alt="" src="https://images-na.ssl-images-amazon.com/images/I/41p2f8xA8TL._SX35_SY35_CR,0,0,35,35_.jpg" height="35" width="35">" & @CRLF & _ " </a></span></span>" & @CRLF & _ " </span></li>" & @CRLF & _ " <li class="a-spacing-mini"><span class="a-list-item">" & @CRLF & _ " <span class="a-button a-button-normal a-button-thumbnail a-button-toggle" id="a-autoid-4"><span class="a-button-inner"><a href="/gp/offer-listing/B011SBR9PS/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=4&amp;mv_size_name=6" class="a-button-text" role="button" id="a-autoid-4-announce">" & @CRLF & _ " <img alt="" src="https://images-na.ssl-images-amazon.com/images/I/311Xw94d26L._SX35_SY35_CR,0,0,35,35_.jpg" height="35" width="35">" & @CRLF & _ " </a></span></span>" & @CRLF & _ " </span></li>" & @CRLF & _ " <li class="a-spacing-mini"><span class="a-list-item">" & @CRLF & _ " <span class="a-button a-button-normal a-button-thumbnail a-button-toggle" id="a-autoid-5"><span class="a-button-inner"><a href="/gp/offer-listing/B07FYS34S4/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=5&amp;mv_size_name=6" class="a-button-text" role="button" id="a-autoid-5-announce">" & @CRLF & _ " <img alt="" src="https://images-na.ssl-images-amazon.com/images/I/41r4qvtmEkL._SX35_SY35_CR,0,0,35,35_.jpg" height="35" width="35">" & @CRLF & _ " </a></span></span>" & @CRLF & _ " </span></li>" & @CRLF & _ " <li class="a-spacing-mini"><span class="a-list-item">" & @CRLF & _ " <span class="a-button a-button-normal a-button-thumbnail a-button-toggle" id="a-autoid-6"><span class="a-button-inner"><a href="/gp/offer-listing/B00MC3TVSK/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=6&amp;mv_size_name=6" class="a-button-text" role="button" id="a-autoid-6-announce">" & @CRLF & _ " <img alt="" src="https://images-na.ssl-images-amazon.com/images/I/31YEDbIcNwL._SX35_SY35_CR,0,0,35,35_.jpg" height="35" width="35">" & @CRLF & _ " </a></span></span>" & @CRLF & _ " </span></li>" & @CRLF & _ " <li class="a-spacing-mini"><span class="a-list-item">" & @CRLF & _ " <span class="a-button a-button-normal a-button-thumbnail a-button-toggle" id="a-autoid-7"><span class="a-button-inner"><a href="/gp/offer-listing/B016W1Z1RC/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=7&amp;mv_size_name=6" class="a-button-text" role="button" id="a-autoid-7-announce">" & @CRLF & _ " <img alt="" src="https://images-na.ssl-images-amazon.com/images/I/41plM8TSFBL._SX35_SY35_CR,0,0,35,35_.jpg" height="35" width="35">" & @CRLF & _ " </a></span></span>" & @CRLF & _ " </span></li>" & @CRLF & _ " <li class="a-spacing-mini"><span class="a-list-item">" & @CRLF & _ " <span class="a-button a-button-normal a-button-thumbnail a-button-toggle" id="a-autoid-8"><span class="a-button-inner"><a href="/gp/offer-listing/B0007L7WPS/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=8&amp;mv_size_name=6" class="a-button-text" role="button" id="a-autoid-8-announce">" & @CRLF & _ " <img alt="" src="https://images-na.ssl-images-amazon.com/images/I/41NGM8gp7hL._SX35_SY35_CR,0,0,35,35_.jpg" height="35" width="35">" & @CRLF & _ " </a></span></span>" & @CRLF & _ " </span></li>" & @CRLF & _ " <li class="a-spacing-mini"><span class="a-list-item">" & @CRLF & _ " <span class="a-button a-button-disabled a-button-thumbnail a-button-toggle" id="a-autoid-9"><span class="a-button-inner"><input disabled="disabled" class="a-button-input" type="submit" aria-labelledby="a-autoid-9-announce"><span class="a-button-text" aria-hidden="true" id="a-autoid-9-announce">" & @CRLF & _ " <img alt="" src="https://images-na.ssl-images-amazon.com/images/I/41WBKxWvoLL._SX35_SY35_CR,0,0,35,35_.jpg" height="35" width="35">" & @CRLF & _ " </span></span></span>" & @CRLF & _ " </span></li>" & @CRLF & _ " <li class="a-spacing-mini"><span class="a-list-item">" & @CRLF & _ " <span class="a-button a-button-disabled a-button-thumbnail a-button-toggle" id="a-autoid-10"><span class="a-button-inner"><input disabled="disabled" class="a-button-input" type="submit" aria-labelledby="a-autoid-10-announce"><span class="a-button-text" aria-hidden="true" id="a-autoid-10-announce">" & @CRLF & _ " <img alt="" src="https://images-na.ssl-images-amazon.com/images/I/41ap6ahxMRL._SX35_SY35_CR,0,0,35,35_.jpg" height="35" width="35">" & @CRLF & _ " </span></span></span>" & @CRLF & _ " </span></li>" & @CRLF & _ " <li class="a-spacing-mini"><span class="a-list-item">" & @CRLF & _ " <span class="a-button a-button-disabled a-button-thumbnail a-button-toggle" id="a-autoid-11"><span class="a-button-inner"><input disabled="disabled" class="a-button-input" type="submit" aria-labelledby="a-autoid-11-announce"><span class="a-button-text" aria-hidden="true" id="a-autoid-11-announce">" & @CRLF & _ " <img alt="" src="https://images-na.ssl-images-amazon.com/images/I/41QD5K54hPL._SX35_SY35_CR,0,0,35,35_.jpg" height="35" width="35">" & @CRLF & _ " </span></span></span>" & @CRLF & _ " </span></li>" & @CRLF & _ " <li class="a-spacing-mini"><span class="a-list-item">" & @CRLF & _ " <span class="a-button a-button-disabled a-button-thumbnail a-button-toggle" id="a-autoid-12"><span class="a-button-inner"><input disabled="disabled" class="a-button-input" type="submit" aria-labelledby="a-autoid-12-announce"><span class="a-button-text" aria-hidden="true" id="a-autoid-12-announce">" & @CRLF & _ " <img alt="" src="https://images-na.ssl-images-amazon.com/images/I/31qtQ78OWiL._SX35_SY35_CR,0,0,35,35_.jpg" height="35" width="35">" & @CRLF & _ " </span></span></span>" & @CRLF & _ " </span></li>" & @CRLF & _ " <li class="a-spacing-mini"><span class="a-list-item">" & @CRLF & _ " <span class="a-button a-button-normal a-button-toggle" id="a-autoid-13"><span class="a-button-inner"><a href="/gp/offer-listing/B00NNA39IE/ref=olp_twister_all?ie=UTF8&amp;mv_color_name=all&amp;mv_size_name=6" class="a-button-text" role="button" id="a-autoid-13-announce">" & @CRLF & _ " Lowest offer for each" & @CRLF & _ " </a></span></span>" & @CRLF & _ " </span></li>" & @CRLF & _ " </ul>" & @CRLF & _ "" & @CRLF & _ " </div>" 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