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 single character of: a, b, c or d
    [[ab][cd]]
  • 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]
  • Character class intersection
    [\w&&[^\d]]
  • 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 = "[:]\s(\".*\")|\d+" Local $sString = "{" & @CRLF & _ " "code": 0," & @CRLF & _ " "data": {" & @CRLF & _ " "album": {" & @CRLF & _ " "count": 2," & @CRLF & _ " "itemlist": [" & @CRLF & _ " {" & @CRLF & _ " "docid": "24100646"," & @CRLF & _ " "id": "24100646"," & @CRLF & _ " "mid": "002mPgSG01LLtu"," & @CRLF & _ " "name": "无名的人"," & @CRLF & _ " "pic": "http://y.gtimg.cn/music/photo_new/T002R180x180M000002mPgSG01LLtu_1.jpg"," & @CRLF & _ " "singer": "毛不易"" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "docid": "3834888"," & @CRLF & _ " "id": "3834888"," & @CRLF & _ " "mid": "0026ttFc17IeE3"," & @CRLF & _ " "name": "无问"," & @CRLF & _ " "pic": "http://y.gtimg.cn/music/photo_new/T002R180x180M0000026ttFc17IeE3_1.jpg"," & @CRLF & _ " "singer": "毛不易"" & @CRLF & _ " }" & @CRLF & _ " ]," & @CRLF & _ " "name": "专辑"," & @CRLF & _ " "order": 2," & @CRLF & _ " "type": 3" & @CRLF & _ " }," & @CRLF & _ " "mv": {" & @CRLF & _ " "count": 2," & @CRLF & _ " "itemlist": [" & @CRLF & _ " {" & @CRLF & _ " "docid": "1449642"," & @CRLF & _ " "id": "1449642"," & @CRLF & _ " "mid": "001UwAbv4H9QVZ"," & @CRLF & _ " "name": "牧马城市"," & @CRLF & _ " "singer": "毛不易"," & @CRLF & _ " "vid": "k002671le5d"" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "docid": "1352908"," & @CRLF & _ " "id": "1352908"," & @CRLF & _ " "mid": "003bjsSu20ltwY"," & @CRLF & _ " "name": "像我这样的人"," & @CRLF & _ " "singer": "毛不易"," & @CRLF & _ " "vid": "y0026hr4b5e"" & @CRLF & _ " }" & @CRLF & _ " ]," & @CRLF & _ " "name": "MV"," & @CRLF & _ " "order": 3," & @CRLF & _ " "type": 4" & @CRLF & _ " }," & @CRLF & _ " "singer": {" & @CRLF & _ " "count": 2," & @CRLF & _ " "itemlist": [" & @CRLF & _ " {" & @CRLF & _ " "docid": "1507534"," & @CRLF & _ " "id": "1507534"," & @CRLF & _ " "mid": "001BHDR33FZVZ0"," & @CRLF & _ " "name": "毛不易"," & @CRLF & _ " "pic": "http://y.gtimg.cn/music/photo_new/T001R150x150M000001BHDR33FZVZ0_3.jpg"," & @CRLF & _ " "singer": "毛不易"" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "docid": "4417724"," & @CRLF & _ " "id": "4417724"," & @CRLF & _ " "mid": "000pEm1i1BkmuD"," & @CRLF & _ " "name": "毛不易的留声机"," & @CRLF & _ " "pic": "http://y.gtimg.cn/music/photo_new/T001R150x150M000000pEm1i1BkmuD_1.jpg"," & @CRLF & _ " "singe": "毛不易的留声机"" & @CRLF & _ " }" & @CRLF & _ " ]," & @CRLF & _ " "name": "歌手"," & @CRLF & _ " "order": 1," & @CRLF & _ " "type": 2" & @CRLF & _ " }," & @CRLF & _ " "song": {" & @CRLF & _ " "count": 4," & @CRLF & _ " "itemlist": [" & @CRLF & _ " {" & @CRLF & _ " "docid": "203514624"," & @CRLF & _ " "id": "203514624"," & @CRLF & _ " "mid": "00375L600p9sxv"," & @CRLF & _ " "name": "像我这样的人"," & @CRLF & _ " "singer": "毛不易"" & @CRLF & _ " }" & @CRLF & _ " {" & @CRLF & _ " "docid": "203451421"," & @CRLF & _ " "id": "203451421"," & @CRLF & _ " "mid": "003kLvu04bLGzi"," & @CRLF & _ " "name": "消愁"," & @CRLF & _ " "singer": "毛不易"" & @CRLF & _ " }" & @CRLF & _ " {" & @CRLF & _ " "docid": "213224236"," & @CRLF & _ " "id": "213224236"," & @CRLF & _ " "mid": "000uhMwj387EBp"," & @CRLF & _ " "name": "牧马城市"," & @CRLF & _ " "singer": "毛不易"" & @CRLF & _ " }" & @CRLF & _ " {" & @CRLF & _ " "docid": "336582682"," & @CRLF & _ " "id": "336582682"," & @CRLF & _ " "mid": "002QhULf16tWw1"," & @CRLF & _ " "name": "无名的人"," & @CRLF & _ " "singer": "毛不易"" & @CRLF & _ " }" & @CRLF & _ " ]," & @CRLF & _ " "name": "单曲"," & @CRLF & _ " "order": 0," & @CRLF & _ " "type": 1" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " "subcode": 0" & @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