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

/
/
gmi

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 = "(?mi)((?:[ ]|^|[^\d\.\:\-\r\n$£])((?:1[0-9]|2[0-4]|0?[1-9]|00|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve)[ ]?[\:\. ]?[ ]?(?:[0-5][0-9]|fifteen|thirty|fou?rty ?five)(?:[ ]?(?:am|pm)|[ ]?o\'?[ ]?clock))(?:\b|$|,\b)|(?:[ ]|^|[^\d\.\:\-\r\n$£])(((?:1[0-9]|2[0-4]|0?[1-9]|00|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve)(?:[ ]?(?:am|pm))|[ ]?o\'?[ ]?clock))(?:\b|$|,\b)|(?:[ ]|^|[^\d\.\:\-\r\n$£])((?:1[0-9]|2[0-4]|0?[1-9]|00|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve)[ ]?[\:\. ][ ]?(?:[0-5][0-9]|fifteen|thirty|fou?rty ?five)(?:\b|$|,\b))|(?:[ ]|^|[^\d\.\:\-\r\n$£])((?:1[0-9]|2[0-4]|0?[1-9]|00) ?(?:PS?T|GMT|∆USA|∆US|ET|BST|∆UK|UK ?[Tt]ime|[Ee]astern [Tt]ime|[Pp]acific [Tt]ime|[Cc]entral [Tt]ime|∆UTC|ACDT|ACST|ACT|ACT|ADT|AEDT|AEST|AFT|AKDT|AKST|AMST|AMT|AMT|ART|AST|AST|AWDT|AWST|AZOST|AZT|BDT|BDT|BIOT|BRST|BRT|BST|BST|BST|BTT|CCT|CDT|CDT|CEDT|CEST|CET|CHADT|CHAST|CHOT|ChST|CHUT|CIST|CIT|CKT|CLST|CLT|COT|CST|CST|CST|CST|CST|CT|CVT|CWST|CXT|DAVT|DDUT|DFT|EASST|ECT|ECT|EDT|EEDT|EEST|EET|EGST|EGT|EIT|EST|EST|FET|FJT|FKST|FKST|FKT|FNT|GALT|GAMT|GFT|GILT|GIT|GMT|GST|GST|GYT|HADT|HAEC|HAST|HKT|HMT|HOVT|HST|IBST|ICT|IDT|IRDT|IRKT|IRST|IST|IST|IST|JST|KGT|KOST|KRAT|KST|LHST|LHST|LINT|MAGT|MART|MAWT|MDT|MET|MEST|MHT|MIST|MMT|MSK|MST|MST|MST|MUT|MVT|MYT|NCT|NDT|NFT|NPT|NST|NT|NUT|NZDT|NZST|OMST|ORAT|PDT|PETT|PGT|PHOT|PKT|PMDT|PMST|PONT|PST|PST|PYST|PYT|RET|ROTT|SAKT|SAMT|SAST|SBT|SCT|SGT|SLST|SRET|SRT|SST|SST|SYOT|TAHT|THA|TFT|TJT|TKT|TLT|TMT|TOT|TVT|ULAT|USZ1|UYST|UYT|UZT|VET|VLAT|VOLT|VOST|VUT|WAKT|WAST|WAT|WEDT|WEST|WET|WST|YAKT))\b)" Local $sString = "4pm" & @CRLF & _ "12:00" & @CRLF & _ "4 CET" & @CRLF & _ "17 UK Time" & @CRLF & _ "" & @CRLF & _ "1200pm" & @CRLF & _ "" & @CRLF & _ "12pm" & @CRLF & _ "14.00" & @CRLF & _ "15.00pm" & @CRLF & _ "" & @CRLF & _ " 33" & @CRLF & _ "" & @CRLF & _ "4pm" & @CRLF & _ "4 pm" & @CRLF & _ " 4:30pm" & @CRLF & _ "3/5/7" & @CRLF & _ "" & @CRLF & _ "Mon" & @CRLF & _ "Tue" & @CRLF & _ "Next Tue " 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