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

r"
"
mg

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)^((?:\[.+?:.*?\])+)(.*)$" Local $sString = "[ar:胡彦斌]" & @CRLF & _ "[ti:月光]" & @CRLF & _ "[00:00.86]月光(秦时明月主题曲)" & @CRLF & _ "[00:06.31]歌手 胡彦斌" & @CRLF & _ "[00:08.68]作词 林文炫" & @CRLF & _ "[00:10.49]作曲 胡彦斌" & @CRLF & _ "[00:20.11]月光色" & @CRLF & _ "[00:22.30]女子香" & @CRLF & _ "[00:24.51]泪断剑" & @CRLF & _ "[00:26.70]情多长" & @CRLF & _ "[00:28.95]有多痛" & @CRLF & _ "[00:30.97]无字想" & @CRLF & _ "[00:33.35][00:33.35]忘了你" & @CRLF & _ "[00:39.43]孤单魂" & @CRLF & _ "[00:41.51]随风荡" & @CRLF & _ "[00:43.57]谁去笑" & @CRLF & _ "[00:45.87]痴情郎" & @CRLF & _ "[00:48.03]这红尘的战场" & @CRLF & _ "[00:52.95]千军万马有谁能称王" & @CRLF & _ "[01:01.69]过情关" & @CRLF & _ "[01:06.00]谁敢闯" & @CRLF & _ "[01:10.42]望明月" & @CRLF & _ "[01:15.62]心悲凉" & @CRLF & _ "[01:19.13]千古恨" & @CRLF & _ "[01:23.45]轮回尝" & @CRLF & _ "[01:27.76]眼一闭" & @CRLF & _ "[01:32.71]谁最狂" & @CRLF & _ "[01:38.90]这世道的无常" & @CRLF & _ "[01:43.23]注定敢爱的人一生伤" & @CRLF & _ "[02:07.33]月光色" & @CRLF & _ "[02:09.20]女子香" & @CRLF & _ "[02:11.49]泪断剑" & @CRLF & _ "[02:13.58]情多长" & @CRLF & _ "[02:15.80]有多痛" & @CRLF & _ "[02:17.87]无字想" & @CRLF & _ "[02:20.23]忘了你" & @CRLF & _ "[02:26.21]孤单魂" & @CRLF & _ "[02:28.20]随风荡" & @CRLF & _ "[02:30.56]谁去笑" & @CRLF & _ "[02:32.64]痴情郎" & @CRLF & _ "[02:34.94]这红尘的战场" & @CRLF & _ "[02:39.70]千军万马有谁能称王" & @CRLF & _ "[02:48.65]过情关" & @CRLF & _ "[02:52.66]谁敢闯" & @CRLF & _ "[02:57.34]望明月" & @CRLF & _ "[03:02.44]心悲凉" & @CRLF & _ "[03:05.97]千古恨" & @CRLF & _ "[03:09.99]轮回尝" & @CRLF & _ "[03:14.67]眼一闭" & @CRLF & _ "[03:19.95]谁最狂" & @CRLF & _ "[03:30.06]过情关" & @CRLF & _ "[03:34.34]谁敢闯" & @CRLF & _ "[03:38.78]望明月" & @CRLF & _ "[03:43.92]心悲凉" & @CRLF & _ "[03:47.58]千古恨" & @CRLF & _ "[03:51.50]轮回尝" & @CRLF & _ "[03:55.96]眼一闭" & @CRLF & _ "[04:01.51]谁最狂" & @CRLF & _ "[04:07.21]这世道的无常" & @CRLF & _ "[04:21.34]注定敢爱的人一生伤" 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