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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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\sid=\"[\s\S]*?dp_productDescription_container_div[\s\S]*?<div\sid=\"productDescription_feature_div[\s\S]*?<div[\s\S]*?<div[\s\S]*?<div\sid=\"productDescription[\s\S]*?>([\s\S]*?<p>[\s\S]*?<\/p>\s*)<\/div>" Local $sString = "<div id="dp_productDescription_container_div" class="feature" data-feature-name="productDescription" data-cel-widget="dp_productDescription_container_div">" & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ " " & @CRLF & _ "" & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ " " & @CRLF & _ " <div id="productDescription_feature_div" data-feature-name="productDescription" data-template-name="productDescription" class="a-row feature" data-cel-widget="productDescription_feature_div">" & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " <div class="a-divider a-divider-section"><div class="a-divider-inner"></div></div>" & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " <h2 class="softlines">" & @CRLF & _ " Product description" & @CRLF & _ " " & @CRLF & _ " </h2>" & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ "" & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ " <div id="productDescription" class="a-section a-spacing-small">" & @CRLF & _ " " & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ "" & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " <!-- show up to 2 reviews by default --> " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " <p>Train better. Look great. The Vazee agility trainer supports your interval workouts with an exciting blend of fashionable colors and a newly designed performance lace mesh upper for support and breathability." & @CRLF & _ " " & @CRLF & _ " </p>" & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " <p>Train better. Look great. The Vazee agility trainer supports your interval workouts with an exciting blend of fashionable colors and a newly designed performance lace mesh upper for support and breathability." & @CRLF & _ " " & @CRLF & _ " </p> " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " </div>" & @CRLF & _ "" & @CRLF & _ " " & @CRLF & _ " <style type="text/css">" & @CRLF & _ "#productDescription {" & @CRLF & _ " color: #333333;" & @CRLF & _ " word-wrap: break-word;" & @CRLF & _ " font-size: small;" & @CRLF & _ " line-height: initial;" & @CRLF & _ " margin: 0.5em 0px 0em 25px;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "#productDescription_feature_div > h2.default {" & @CRLF & _ " color: #CC6600;" & @CRLF & _ " font-size: medium;" & @CRLF & _ " margin: 0 0 0.25em;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "#productDescription_feature_div > h2.books {" & @CRLF & _ " color:#333 !important;" & @CRLF & _ " font-size:21px !important;" & @CRLF & _ " line-height: 1.3;" & @CRLF & _ " padding-bottom: 4px;" & @CRLF & _ " font-weight: normal;" & @CRLF & _ " margin: 0px;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "#productDescription_feature_div > h2.softlines {" & @CRLF & _ " color:#333 !important; " & @CRLF & _ " font-size:21px !important;" & @CRLF & _ " line-height: 1.3;" & @CRLF & _ " padding-bottom: 4px;" & @CRLF & _ " font-weight: bold;" & @CRLF & _ " margin: 0px;" & @CRLF & _ "}" & @CRLF & _ "#productDescription > p, #productDescription > div, #productDescription > table {" & @CRLF & _ " margin: 0 0 1em 0;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "#productDescription p {" & @CRLF & _ " margin: 0em 0 1em 1em;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "#productDescription h3 {" & @CRLF & _ " font-weight: normal;" & @CRLF & _ " color: #333333;" & @CRLF & _ " font-size: 1.23em;" & @CRLF & _ " clear: left;" & @CRLF & _ " margin: 0.75em 0px 0.375em -15px;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "#productDescription table {" & @CRLF & _ " border-collapse: inherit !important;" & @CRLF & _ " margin-bottom: 0;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "#productDescription table img {" & @CRLF & _ " max-width: inherit !important;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "#productDescription table td {" & @CRLF & _ " font-size: small;" & @CRLF & _ " vertical-align: inherit !important;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "#productDescription ul li {" & @CRLF & _ " margin: 0 0 0 20px;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "#productDescription ul li ul {" & @CRLF & _ " list-style-type: disc !important;" & @CRLF & _ " margin-left: 20px !important;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "#productDescription ul ul li {" & @CRLF & _ " list-style-type: disc !important;" & @CRLF & _ " margin-left: 20px !important;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "#productDescription > ul ul li {" & @CRLF & _ " list-style-type: disc !important;" & @CRLF & _ "} " & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "#productDescription ul li ul li {" & @CRLF & _ " margin: 0 0 0 20px;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "#productDescription .aplus p {" & @CRLF & _ " margin: 0 0 1em 0;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "#productDescription small {" & @CRLF & _ " font-size: smaller;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "#productDescription.prodDescWidth {" & @CRLF & _ " max-width: 1000px" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "</style>" & @CRLF & _ "" & @CRLF & _ "<!-- Used to set table width because AUI is overriding the width attribute of the tables coming in description -->" & @CRLF & _ "<script type="text/javascript">" & @CRLF & _ "P.when('jQuery').execute(function($){" & @CRLF & _ " $("#productDescription table").each(function() {" & @CRLF & _ " var width = $(this).attr('width');" & @CRLF & _ " if (width) width += 'px';" & @CRLF & _ " else width = 'auto';" & @CRLF & _ " $(this).css('width', width);" & @CRLF & _ "" & @CRLF & _ " var padding = $(this).attr('cellpadding');" & @CRLF & _ " if (padding) padding += 'px';" & @CRLF & _ " else padding = '0px';" & @CRLF & _ " $(this).css('padding', padding);" & @CRLF & _ " });" & @CRLF & _ "});" & @CRLF & _ "</script>" & @CRLF & _ "" & @CRLF & _ " " & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " </div>" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ "" & @CRLF & _ " " & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @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