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
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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

/
/
gm

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)[0-9]{3}[M]" Local $sString = "[root@barpbli24149399 log]# ls -alhr | grep -E [\d\d\dM]" & @CRLF & _ "-rw------- 1 root root 2.1K Nov 12 20:39 vmware-vmtoolsd-root.log" & @CRLF & _ "-rw------- 1 root root 719 Mar 11 2021 vmware-network.log" & @CRLF & _ "-rw------- 1 root root 719 Mar 11 2021 vmware-network.2.log" & @CRLF & _ "-rw------- 1 root root 741 Mar 11 2021 vmware-network.1.log" & @CRLF & _ "drwxr-xr-x. 2 root root 4.0K Dec 14 2020 tuned" & @CRLF & _ "-rw-r----- 1 root root 2.2K Mar 11 2021 tsy-install-hpsa.log" & @CRLF & _ "-rw-r--r-- 1 root root 184 Nov 12 20:39 TSM_CAD_-_BARPBLI24149399_FS.dsminfo" & @CRLF & _ "drwxrwxrwx 2 root root 4.0K Nov 28 06:51 tsm" & @CRLF & _ "-rw-------. 1 root root 16M Nov 28 09:10 tallylog" & @CRLF & _ "-rw------- 1 root root 139 Mar 16 2021 sudolog" & @CRLF & _ "drwxr-x---. 2 sssd sssd 4.0K Nov 13 03:08 sssd" & @CRLF & _ "-rw------- 1 root root 220 Mar 11 2021 serverprofile.log" & @CRLF & _ "-rw-r----- 1 root root 157K May 29 2022 seclog.log-20220529" & @CRLF & _ "-rw-r----- 1 root root 158K May 22 2022 seclog.log-20220522" & @CRLF & _ "-rw-r----- 1 root root 161K May 15 2022 seclog.log-20220515" & @CRLF & _ "-rw-r----- 1 root root 158K May 8 2022 seclog.log-20220508" & @CRLF & _ "-rw-r----- 1 root root 157K May 1 2022 seclog.log-20220501" & @CRLF & _ "-rw-r----- 1 root root 156K Mar 27 2022 seclog.log-20220326" & @CRLF & _ "-rw-r----- 1 root root 161K Mar 20 2022 seclog.log-20220319" & @CRLF & _ "-rw-r----- 1 root root 157K Mar 13 2022 seclog.log-20220312" & @CRLF & _ "-rw-r----- 1 root root 158K Mar 6 2022 seclog.log-20220305" & @CRLF & _ "-rw-r----- 1 root root 158K May 30 2021 seclog.log-20210529" & @CRLF & _ "-rw-r----- 1 root root 157K May 23 2021 seclog.log-20210522" & @CRLF & _ "-rw-r----- 1 root root 158K May 16 2021 seclog.log-20210515" & @CRLF & _ "-rw-r----- 1 root root 157K May 9 2021 seclog.log-20210508" & @CRLF & _ "-rw-r----- 1 root root 157K May 2 2021 seclog.log-20210501" & @CRLF & _ "-rw-r----- 1 root root 156K Mar 28 2021 seclog.log-20210326" & @CRLF & _ "-rw------- 1 root root 107K Mar 21 2021 seclog.log-20210319" & @CRLF & _ "drwx------. 3 root root 4.0K May 10 2022 samba" & @CRLF & _ "drwxr-xr-x. 2 root root 4.0K Nov 28 00:00 sa" & @CRLF & _ "drwxr-xr-x. 2 root root 4.0K Nov 27 03:19 rhsm" & @CRLF & _ "drwxr-xr-x 2 root root 4.0K Nov 12 20:31 rear" & @CRLF & _ "drwxr-xr-x 4 root root 4.0K Apr 16 2022 puppetlabs" & @CRLF & _ "drwxr-xr-x. 2 root root 4.0K Aug 17 2016 prelink" & @CRLF & _ "drwxr-xr-x 3 root root 4.0K Mar 11 2021 opsware" & @CRLF & _ "drwxr-xr-x. 2 ntp ntp 4.0K Jun 1 2020 ntpstats" & @CRLF & _ "-rw-r--r-- 1 root root 4.8K Mar 18 2021 ntp" & @CRLF & _ "-rw-r----- 1 root root 1.2M Nov 13 03:15 messages-20221113" & @CRLF & _ "-rw-r----- 1 root root 13M Aug 7 03:15 messages-20220807" & @CRLF & _ "-rw-r----- 1 root root 29M Jul 31 03:35 messages-20220731" & @CRLF & _ "-rw-r----- 1 root root 29M Jul 24 03:15 messages-20220724" & @CRLF & _ "-rw-r----- 1 root root 29M Jul 17 03:20 messages-20220717" & @CRLF & _ "-rw-r----- 1 root root 29M Jul 10 03:50 messages-20220710" & @CRLF & _ "-rw-r----- 1 root root 29M Jul 3 03:14 messages-20220703" & @CRLF & _ "-rw-r----- 1 root root 29M Jun 26 03:24 messages-20220626" & @CRLF & _ "-rw-r----- 1 root root 29M Jun 19 03:20 messages-20220619" & @CRLF & _ "-rw-r----- 1 root root 29M Jun 12 03:24 messages-20220612" & @CRLF & _ "-rw-r----- 1 root root 29M Jun 5 03:20 messages-20220605" & @CRLF & _ "-rw-r----- 1 root root 29M May 29 2022 messages-20220529" & @CRLF & _ "-rw-r----- 1 root root 29M May 22 2022 messages-20220522" & @CRLF & _ "-rw-r----- 1 root root 29M May 15 2022 messages-20220515" & @CRLF & _ "-rw-r----- 1 root root 29M May 8 2022 messages-20220508" & @CRLF & _ "-rw-r----- 1 root root 29M May 1 2022 messages-20220501" & @CRLF & _ "-rw-r----- 1 root root 29M Apr 24 2022 messages-20220424" & @CRLF & _ "-rw-r----- 1 root root 29M Apr 17 2022 messages-20220417" & @CRLF & _ "-rw-r----- 1 root root 29M Apr 10 2022 messages-20220410" & @CRLF & _ "-rw-r----- 1 root root 29M Apr 3 2022 messages-20220403" & @CRLF & _ "-rw-r----- 1 root root 29M Mar 27 2022 messages-20220327" & @CRLF & _ "-rw-r----- 1 root root 29M Mar 20 2022 messages-20220320" & @CRLF & _ "-rw-r----- 1 root root 29M Mar 13 2022 messages-20220313" & @CRLF & _ "-rw-r----- 1 root root 29M Mar 6 2022 messages-20220306" & @CRLF & _ "-rw-r----- 1 root root 29M Feb 27 2022 messages-20220227" & @CRLF & _ "-rw-r----- 1 root root 29M Feb 20 2022 messages-20220220" & @CRLF & _ "-rw-r----- 1 root root 29M Feb 13 2022 messages-20220213" & @CRLF & _ "-rw-r----- 1 root root 29M Feb 6 2022 messages-20220206" & @CRLF & _ "-rw-r----- 1 root root 29M Jan 30 2022 messages-20220130" & @CRLF & _ "-rw-r----- 1 root root 29M Jan 23 2022 messages-20220123" & @CRLF & _ "-rw-r----- 1 root root 29M Jan 16 2022 messages-20220116" & @CRLF & _ "-rw-r----- 1 root root 29M Jan 9 2022 messages-20220109" & @CRLF & _ "-rw-r----- 1 root root 29M Jan 2 2022 messages-20220102" & @CRLF & _ "-rw-r----- 1 root root 29M Dec 26 2021 messages-20211226" & @CRLF & _ "-rw-r----- 1 root root 29M Dec 19 2021 messages-20211219" & @CRLF & _ "-rw-r----- 1 root root 29M Dec 12 2021 messages-20211212" & @CRLF & _ "-rw-r----- 1 root root 29M Dec 5 2021 messages-20211205" & @CRLF & _ "-rw-r----- 1 root root 29M Nov 28 2021 messages-20211128" & @CRLF & _ "-rw-r----- 1 root root 29M Nov 21 2021 messages-20211121" & @CRLF & _ "-rw-r----- 1 root root 29M Nov 14 2021 messages-20211114" & @CRLF & _ "-rw-r----- 1 root root 29M Nov 7 2021 messages-20211107" & @CRLF & _ "-rw-r----- 1 root root 29M Oct 31 2021 messages-20211031" & @CRLF & _ "-rw-r----- 1 root root 29M Oct 24 2021 messages-20211024" & @CRLF & _ "-rw-r----- 1 root root 29M Oct 17 2021 messages-20211017" & @CRLF & _ "-rw-r----- 1 root root 29M Oct 10 2021 messages-20211010" & @CRLF & _ "-rw-r----- 1 root root 30M Oct 3 2021 messages-20211003" & @CRLF & _ "-rw-r----- 1 root root 31M Sep 26 2021 messages-20210926" & @CRLF & _ "-rw-r----- 1 root root 31M Sep 19 2021 messages-20210919" & @CRLF & _ "-rw-r----- 1 root root 30M Sep 12 2021 messages-20210912" & @CRLF & _ "-rw-r----- 1 root root 30M Sep 5 2021 messages-20210905" & @CRLF & _ "-rw-r----- 1 root root 30M Aug 29 2021 messages-20210829" & @CRLF & _ "-rw-r----- 1 root root 34M Aug 22 2021 messages-20210822" & @CRLF & _ "-rw-r----- 1 root root 34M Aug 15 2021 messages-20210815" & @CRLF & _ "-rw-r----- 1 root root 34M Aug 8 2021 messages-20210808" & @CRLF & _ "-rw-r----- 1 root root 34M Aug 1 2021 messages-20210801" & @CRLF & _ "-rw-r----- 1 root root 34M Jul 25 2021 messages-20210725" & @CRLF & _ "-rw-r----- 1 root root 34M Jul 18 2021 messages-20210718" & @CRLF & _ "-rw-r----- 1 root root 34M Jul 11 2021 messages-20210711" & @CRLF & _ "-rw-r----- 1 root root 34M Jul 4 2021 messages-20210704" & @CRLF & _ "-rw-r----- 1 root root 34M Jun 27 2021 messages-20210627" & @CRLF & _ "-rw-r----- 1 root root 34M Jun 20 2021 messages-20210620" & @CRLF & _ "-rw-r----- 1 root root 34M Jun 13 2021 messages-20210613" & @CRLF & _ "-rw-r----- 1 root root 32M Jun 6 2021 messages-20210606" & @CRLF & _ "-rw-r----- 1 root root 34M May 30 2021 messages-20210530" & @CRLF & _ "-rw-r----- 1 root root 34M May 23 2021 messages-20210523" & @CRLF & _ "-rw-r----- 1 root root 34M May 16 2021 messages-20210516" & @CRLF & _ "-rw-r----- 1 root root 34M May 9 2021 messages-20210509" & @CRLF & _ "-rw-r----- 1 root root 34M May 2 2021 messages-20210502" & @CRLF & _ "-rw-r----- 1 root root 34M Apr 25 2021 messages-20210425" & @CRLF & _ "-rw-r----- 1 root root 34M Apr 18 2021 messages-20210418" & @CRLF & _ "-rw-r----- 1 root root 34M Apr 11 2021 messages-20210411" & @CRLF & _ "-rw-r----- 1 root root 34M Apr 4 2021 messages-20210404" & @CRLF & _ "-rw-r----- 1 root root 34M Mar 28 2021 messages-20210328" & @CRLF & _ "-rw-r----- 1 root root 14M Mar 21 2021 messages-20210321" & @CRLF & _ "-rw-------. 1 root root 669K Mar 14 2021 messages-20210314" & @CRLF & _ "-rw-r--r--. 1 root root 140M Nov 28 09:11 lastlog" & @CRLF & _ "-rw------- 1 root root 106K Mar 18 2021 hawkey.log-20210321" & @CRLF & _ "-rw-r--r--. 1 root root 80K Mar 14 2021 hawkey.log-20210314" & @CRLF & _ "-rw------- 1 root root 0 Mar 21 2021 hawkey.log" & @CRLF & _ "-rw-r--r--. 1 root root 193 Dec 18 2020 grubby_prune_debug" & @CRLF & _ "-rw------- 1 root root 6.0K Mar 18 2021 dnf.rpm.log-20210321" & @CRLF & _ "-rw-r--r--. 1 root root 126K Mar 14 2021 dnf.rpm.log-20210314" & @CRLF & _ "-rw------- 1 root root 0 Mar 21 2021 dnf.rpm.log" & @CRLF & _ "-rw------- 1 root root 175K Mar 18 2021 dnf.log-20210321" & @CRLF & _ "-rw-r--r--. 1 root root 418K Mar 14 2021 dnf.log-20210314" & @CRLF & _ "-rw------- 1 root root 0 Mar 21 2021 dnf.log" & @CRLF & _ "-rw------- 1 root root 727K Mar 18 2021 dnf.librepo.log-20210321" & @CRLF & _ "-rw-r--r--. 1 root root 789K Mar 14 2021 dnf.librepo.log-20210314" & @CRLF & _ "-rw------- 1 root root 0 Mar 21 2021 dnf.librepo.log" & @CRLF & _ "-rw-r--r-- 1 root root 116K Nov 12 20:35 dmesg.old" & @CRLF & _ "-rw-r--r-- 1 root root 116K Nov 12 20:39 dmesg" & @CRLF & _ "-rw------- 1 root root 19M Nov 28 09:10 cron" & @CRLF & _ "drwxr-xr-x. 2 chrony chrony 4.0K Jan 10 2019 chrony" & @CRLF & _ "-rw------- 1 root root 21K Mar 19 2021 boot.log-20210319" & @CRLF & _ "-rw------- 1 root root 41K Mar 18 2021 boot.log-20210318" & @CRLF & _ "-rw------- 1 root root 42K Mar 12 2021 boot.log-20210312" & @CRLF & _ "drwx------. 2 root root 4.0K Nov 4 18:00 audit" & @CRLF & _ "drwxr-xr-x. 21 root root 4.0K Mar 11 2021 .." & @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