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

/
/
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 = "<style>[\s\S]*<\/style>" Local $sString = "<!--" & @CRLF & _ " * @Descripttion: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE" & @CRLF & _ " * @version: April 2021 (version 1.56)" & @CRLF & _ " * @Author: ZhangKe" & @CRLF & _ " * @Date: 2022-04-15 11:12:09" & @CRLF & _ " * @LastEditors: ZhangKe" & @CRLF & _ " * @LastEditTime: 2022-04-15 11:20:25" & @CRLF & _ " * @FilePath: \19_Node.js\13_clocl时钟案例\index.html" & @CRLF & _ "-->" & @CRLF & _ "<!DOCTYPE html>" & @CRLF & _ "<html lang="en">" & @CRLF & _ "" & @CRLF & _ "<head>" & @CRLF & _ " <meta charset="UTF-8">" & @CRLF & _ " <meta name="viewport" content="width=device-width, initial-scale=1.0">" & @CRLF & _ " <meta http-equiv="X-UA-Compatible" content="ie=edge">" & @CRLF & _ " <title>index首页</title>" & @CRLF & _ " <style>" & @CRLF & _ " html," & @CRLF & _ " body {" & @CRLF & _ " margin: 0;" & @CRLF & _ " padding: 0;" & @CRLF & _ " height: 100%;" & @CRLF & _ " background-image: linear-gradient(to bottom right, red, gold);" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " .box {" & @CRLF & _ " width: 400px;" & @CRLF & _ " height: 250px;" & @CRLF & _ " background-color: rgba(255, 255, 255, 0.6);" & @CRLF & _ " border-radius: 6px;" & @CRLF & _ " position: absolute;" & @CRLF & _ " left: 50%;" & @CRLF & _ " top: 40%;" & @CRLF & _ " transform: translate(-50%, -50%);" & @CRLF & _ " box-shadow: 1px 1px 10px #fff;" & @CRLF & _ " text-shadow: 0px 1px 30px white;" & @CRLF & _ "" & @CRLF & _ " display: flex;" & @CRLF & _ " justify-content: space-around;" & @CRLF & _ " align-items: center;" & @CRLF & _ " font-size: 70px;" & @CRLF & _ " user-select: none;" & @CRLF & _ " padding: 0 20px;" & @CRLF & _ "" & @CRLF & _ " /* 盒子投影 */" & @CRLF & _ " -webkit-box-reflect: below 0px -webkit-gradient(linear, left top, left bottom, from(transparent), color-stop(0%, transparent), to(rgba(250, 250, 250, .2)));" & @CRLF & _ " }" & @CRLF & _ " </style>" & @CRLF & _ "</head>" & @CRLF & _ "" & @CRLF & _ "<body>" & @CRLF & _ " <div class="box">" & @CRLF & _ " <div id="HH">00</div>" & @CRLF & _ " <div>:</div>" & @CRLF & _ " <div id="mm">00</div>" & @CRLF & _ " <div>:</div>" & @CRLF & _ " <div id="ss">00</div>" & @CRLF & _ " </div>" & @CRLF & _ "" & @CRLF & _ " <script>" & @CRLF & _ " window.addEventListener('load', function (evt) {" & @CRLF & _ " // 定时器,每隔 1 秒执行 1 次" & @CRLF & _ " setInterval(() => {" & @CRLF & _ " var dt = new Date()" & @CRLF & _ " var HH = dt.getHours()" & @CRLF & _ " var mm = dt.getMinutes()" & @CRLF & _ " var ss = dt.getSeconds()" & @CRLF & _ "" & @CRLF & _ " // 为页面上的元素赋值" & @CRLF & _ " document.querySelector('#HH').innerHTML = padZero(HH)" & @CRLF & _ " document.querySelector('#mm').innerHTML = padZero(mm)" & @CRLF & _ " document.querySelector('#ss').innerHTML = padZero(ss)" & @CRLF & _ " }, 1000)" & @CRLF & _ " });" & @CRLF & _ "" & @CRLF & _ " // 补零函数" & @CRLF & _ " function padZero(n) {" & @CRLF & _ " return n > 9 ? n : '0' + n" & @CRLF & _ " }" & @CRLF & _ " </script>" & @CRLF & _ "</body>" & @CRLF & _ "" & @CRLF & _ "</html>" 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