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

/
/
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 = "(@.*?:[^}{@]+(\{(?:[^}{]+|\{(?:[^}{]+|\{[^}{]*\})*\})*\}))" Local $sString = "CSS @media selector" & @CRLF & _ ".CSS Code sample test" & @CRLF & _ "@media screen and (min-width:0) and (max-width:640px) {" & @CRLF & _ " body.overlap .page-title .wf-wrap {" & @CRLF & _ " padding-top: 0!important;" & @CRLF & _ " padding-bottom: 4px!important" & @CRLF & _ " }" & @CRLF & _ " .h3-size {" & @CRLF & _ " font: normal 17px / 21px "Roboto",Helvetica,Arial,Verdana,sans-serif!important" & @CRLF & _ " }" & @CRLF & _ " body.breadcrumbs.breadcrumbs-bg {" & @CRLF & _ " margin-top: 0!important" & @CRLF & _ " }" & @CRLF & _ " .page-title .breadcrumbs,.page-title .breadcrumbs a {" & @CRLF & _ " font-size: 11px!important" & @CRLF & _ " }" & @CRLF & _ "}" & @CRLF & _ "@-webkit-keyframes fadeIn {0% { opacity: 0; }100% { opacity: 1; }}" & @CRLF & _ "" & @CRLF & _ "@media screen and (max-width:200px){.sidebar-content {margin-bottom:20px}" & @CRLF & _ ".cat-item {padding:7px}" & @CRLF & _ ".widget_1 {padding-right:0}" & @CRLF & _ "}" & @CRLF & _ "/* TEST NESTED @media: */" & @CRLF & _ "@media screen and (max-width:200px){.sidebar-content {margin-bottom:20px}" & @CRLF & _ ".cat-item {padding:7px}" & @CRLF & _ "/* TEST NESTED @media capturing everything, comments too */" & @CRLF & _ "@media screen and (max-width:359px){.sidebar-content {margin-bottom:20px}" & @CRLF & _ ".cat-item {padding:7px}" & @CRLF & _ ".widget_1 {padding-right:0}" & @CRLF & _ "}" & @CRLF & _ ".widget_1 {padding-right:0}" & @CRLF & _ "}" & @CRLF & _ "@font-face { font-family: dashicons; src: url("https://emd4.com/"); }" & @CRLF & _ ".h3-size {" & @CRLF & _ " font-style: normal" & @CRLF & _ "}" & @CRLF & _ "@media(min-width:768px){.vc_col-sm-1,.vc_col-sm-10,.vc_col-sm-11,.vc_col-sm-12,.vc_col-sm-2,.vc_col-sm-3,.vc_col-sm-4,.vc_col-sm-5,.vc_col-sm-6,.vc_col-sm-7,.vc_col-sm-8,.vc_col-sm-9{float:left}" & @CRLF & _ ".vc_col-sm-12{width:100%!important}" & @CRLF & _ ".vc_col-sm-11{width:91.66666667%}" & @CRLF & _ ".vc_col-sm-10{width:83.33333333%}" & @CRLF & _ ".vc_col-sm-9{width:75%}" & @CRLF & _ ".vc_col-sm-8{width:66.66666667%}" & @CRLF & _ ".vc_col-sm-7{width:58.33333333%}" & @CRLF & _ ".vc_col-sm-6{width:50%}" & @CRLF & _ ".vc_col-sm-5{width:41.66666667%}" & @CRLF & _ ".vc_col-sm-4{width:33.33333333%}" & @CRLF & _ ".vc_col-sm-3{width:25%}" & @CRLF & _ ".vc_col-sm-2{width:16.66666667%}" & @CRLF & _ ".vc_col-sm-1{width:8.33333333%}" & @CRLF & _ ".vc_col-sm-pull-12{right:100%}" & @CRLF & _ ".vc_col-sm-pull-11{right:91.66666667%}" & @CRLF & _ ".vc_col-sm-pull-10{right:83.33333333%}" & @CRLF & _ ".vc_col-sm-pull-9{right:75%}" & @CRLF & _ ".vc_col-sm-pull-8{right:66.66666667%}" & @CRLF & _ ".vc_col-sm-pull-7{right:58.33333333%}" & @CRLF & _ ".vc_col-sm-pull-6{right:50%}" & @CRLF & _ ".vc_col-sm-pull-5{right:41.66666667%}" & @CRLF & _ ".vc_col-sm-pull-4{right:33.33333333%}" & @CRLF & _ ".vc_col-sm-pull-3{right:25%}" & @CRLF & _ ".vc_col-sm-pull-2{right:16.66666667%}" & @CRLF & _ ".vc_col-sm-pull-1{right:8.33333333%}" & @CRLF & _ ".vc_col-sm-pull-0{right:auto}" & @CRLF & _ ".vc_col-sm-push-12{left:100%}" & @CRLF & _ ".vc_col-sm-push-11{left:91.66666667%}" & @CRLF & _ ".vc_col-sm-push-10{left:83.33333333%}" & @CRLF & _ ".vc_col-sm-push-9{left:75%}" & @CRLF & _ ".vc_col-sm-push-8{left:66.66666667%}" & @CRLF & _ ".vc_col-sm-push-7{left:58.33333333%}" & @CRLF & _ ".vc_col-sm-push-6{left:50%}" & @CRLF & _ ".vc_col-sm-push-5{left:41.66666667%}" & @CRLF & _ ".vc_col-sm-push-4{left:33.33333333%}" & @CRLF & _ ".vc_col-sm-push-3{left:25%}" & @CRLF & _ ".vc_col-sm-push-2{left:16.66666667%}" & @CRLF & _ ".vc_col-sm-push-1{left:8.33333333%}" & @CRLF & _ ".vc_col-sm-push-0{left:auto}" & @CRLF & _ ".vc_col-sm-offset-12{margin-left:100%}" & @CRLF & _ ".vc_col-sm-offset-11{margin-left:91.66666667%}" & @CRLF & _ ".vc_col-sm-offset-10{margin-left:83.33333333%}" & @CRLF & _ ".vc_col-sm-offset-9{margin-left:75%}" & @CRLF & _ ".vc_col-sm-offset-8{margin-left:66.66666667%}" & @CRLF & _ ".vc_col-sm-offset-7{margin-left:58.33333333%}" & @CRLF & _ ".vc_col-sm-offset-6{margin-left:50%}" & @CRLF & _ ".vc_col-sm-offset-5{margin-left:41.66666667%}" & @CRLF & _ ".vc_col-sm-offset-4{margin-left:33.33333333%}" & @CRLF & _ ".vc_col-sm-offset-3{margin-left:25%}" & @CRLF & _ ".vc_col-sm-offset-2{margin-left:16.66666667%}" & @CRLF & _ ".vc_col-sm-offset-1{margin-left:8.33333333%}" & @CRLF & _ ".vc_col-sm-offset-0{margin-left:0}}" 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