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"
"
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)^[a-z_][a-z0-9_-]{0,30}[a-z0-9_$-]?:[^:]*:\d+:\d+:[^:]*:[^:]*:[^:]*$" Local $sString = "root:x:0:0:root:/root:/bin/bash" & @CRLF & _ "daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin" & @CRLF & _ "bin:x:2:2:bin:/bin:/usr/sbin/nologin" & @CRLF & _ "sys:x:3:3:sys:/dev:/usr/sbin/nologin" & @CRLF & _ "sync:x:4:65534:sync:/bin:/bin/sync" & @CRLF & _ "games:x:5:60:games:/usr/games:/usr/sbin/nologin" & @CRLF & _ "man:x:6:12:man:/var/cache/man:/usr/sbin/nologin" & @CRLF & _ "lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin" & @CRLF & _ "mail:x:8:8:mail:/var/mail:/usr/sbin/nologin" & @CRLF & _ "news:x:9:9:news:/var/spool/news:/usr/sbin/nologin" & @CRLF & _ "uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin" & @CRLF & _ "proxy:x:13:13:proxy:/bin:/usr/sbin/nologin" & @CRLF & _ "www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin" & @CRLF & _ "backup:x:34:34:backup:/var/backups:/usr/sbin/nologin" & @CRLF & _ "list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin" & @CRLF & _ "mysql:x:115:124:MySQL Server,,,:/var/lib/mysql:/bin/false" & @CRLF & _ "sshd:x:116:65534::/var/run/sshd:/usr/sbin/nologin" & @CRLF & _ "guest:x:118:125:Guest,,,:/tmp/guest-home.phc17z:/bin/bash" & @CRLF & _ "gordon:x:1004:1000:Assaf Gordon,,,,:/home/gordon:/bin/bash" & @CRLF & _ "charles:x:1005:1000:Charles,,,,:/home/charles:/bin/bash" & @CRLF & _ "alice:x:1006:1000:Alice,,,,:/home/alice:/bin/bash" & @CRLF & _ "bob:x:1007:1000:Bob,,,,:/home/bob:/bin/bash" & @CRLF & _ "postgres:x:119:126:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash" & @CRLF & _ "rabbitmq:x:125:138:RabbitMQ messaging server,,,:/var/lib/rabbitmq:/bin/false" & @CRLF & _ "redis:x:126:140:redis server,,,:/var/lib/redis:/bin/false" & @CRLF & _ "postfix:x:127:141::/var/spool/postfix:/bin/false" & @CRLF & _ "" & @CRLF & _ "root::0:0:root:/root:/bin/sh" & @CRLF & _ "bin:*:1:1:bin:/bin:/bin/false" & @CRLF & _ "daemon:*:2:2:daemon:/sbin:/bin/false" & @CRLF & _ "adm:*:3:4:adm:/var/account:/bin/false" & @CRLF & _ "lp:*:4:7:lp:/var/spool/lpd:/bin/false" & @CRLF & _ "sync:*:5:0:sync:/sbin:/bin/sync" & @CRLF & _ "shutdown:*:6:0:shutdown:/sbin:/sbin/shutdown" & @CRLF & _ "halt:*:7:0:halt:/sbin:/sbin/halt" & @CRLF & _ "mail:*:8:12:mail:/var/mail:/bin/false" & @CRLF & _ "news:*:9:13:news:/home/services/news:/bin/false" & @CRLF & _ "uucp:*:10:14:uucp:/var/spool/uucp:/bin/false" & @CRLF & _ "operator:*:11:0:operator:/root:/bin/false" & @CRLF & _ "games:*:12:20:games:/usr/games:/bin/false" & @CRLF & _ "ftp:*:14:50:FTP User:/home/services/ftp:/bin/false" & @CRLF & _ "http:*:51:51:HTTP User:/home/services/httpd:/bin/false" & @CRLF & _ "stats:*:123:123:Statistics generator user:/usr/share/empty:/bin/false" & @CRLF & _ "nobody:*:99:99:Nobody:/usr/share/empty:/bin/false" & @CRLF & _ "" & @CRLF & _ "root:x:0:0:root:/root:/bin/bash" & @CRLF & _ "bin:x:1:1:bin:/bin:/sbin/nologin" & @CRLF & _ "daemon:x:2:2:daemon:/sbin:/sbin/nologin" & @CRLF & _ "adm:x:3:4:adm:/var/adm:/sbin/nologin" & @CRLF & _ "lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin" & @CRLF & _ "sync:x:5:0:sync:/sbin:/bin/sync" & @CRLF & _ "shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown" & @CRLF & _ "halt:x:7:0:halt:/sbin:/sbin/halt" & @CRLF & _ "mail:x:8:12:mail:/var/spool/mail:/sbin/nologin" & @CRLF & _ "news:x:9:13:news:/etc/news:" & @CRLF & _ "uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin" & @CRLF & _ "operator:x:11:0:operator:/root:/sbin/nologin" & @CRLF & _ "games:x:12:100:games:/usr/games:/sbin/nologin" & @CRLF & _ "gopher:x:13:30:gopher:/var/gopher:/sbin/nologin" & @CRLF & _ "ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin" & @CRLF & _ "nobody:x:99:99:Nobody:/:/sbin/nologin" & @CRLF & _ "nscd:x:28:28:NSCD Daemon:/:/sbin/nologin" & @CRLF & _ "vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin" & @CRLF & _ "pcap:x:77:77::/var/arpwatch:/sbin/nologin" & @CRLF & _ "ntp:x:38:38::/etc/ntp:/sbin/nologin" & @CRLF & _ "dbus:x:81:81:System message bus:/:/sbin/nologin" & @CRLF & _ "avahi:x:70:70:Avahi daemon:/:/sbin/nologin" & @CRLF & _ "rpc:x:32:32:Portmapper RPC user:/:/sbin/nologin" & @CRLF & _ "apache:x:48:48:Apache:/var/www:/sbin/nologin" & @CRLF & _ "mailnull:x:47:47::/var/spool/mqueue:/sbin/nologin" & @CRLF & _ "smmsp:x:51:51::/var/spool/mqueue:/sbin/nologin" & @CRLF & _ "hsqldb:x:96:96::/var/lib/hsqldb:/sbin/nologin" & @CRLF & _ "sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin" & @CRLF & _ "rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin" & @CRLF & _ "nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin" & @CRLF & _ "xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin" & @CRLF & _ "haldaemon:x:68:68:HAL daemon:/:/sbin/nologin" & @CRLF & _ "avahi-autoipd:x:100:102:avahi-autoipd:/var/lib/avahi-autoipd:/sbin/nologin" & @CRLF & _ "gdm:x:42:42::/var/gdm:/sbin/nologin" & @CRLF & _ "jackhuang:x:501:501::/home/jackhuang:/bin/bash" & @CRLF & _ "mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash" & @CRLF & _ "roye:x:502:502::/home/roye:/bin/bash" & @CRLF & _ "ecnet:x:503:503::/var/www/html:/bin/bash" & @CRLF & _ "phoebe:x:504:504::/home/phoebe:/bin/bash" 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