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)^([^\s]*)\s*([^\s]*)\s*([^\s]*)\s*([^\s]*)\s*([^\s]*)\s*([^\s]*)\s*([^\s]*)\s*(.*)$" Local $sString = "UID PID PPID C STIME TTY TIME CMD" & @CRLF & _ "root 1 0 0 17:19 ? 00:00:00 /sbin/init" & @CRLF & _ "root 2 0 0 17:19 ? 00:00:00 [kthreadd]" & @CRLF & _ "root 3 2 0 17:19 ? 00:00:00 [migration/0]" & @CRLF & _ "root 4 2 0 17:19 ? 00:00:00 [ksoftirqd/0]" & @CRLF & _ "root 5 2 0 17:19 ? 00:00:00 [migration/0]" & @CRLF & _ "root 6 2 0 17:19 ? 00:00:00 [watchdog/0]" & @CRLF & _ "root 7 2 0 17:19 ? 00:00:00 [migration/1]" & @CRLF & _ "root 8 2 0 17:19 ? 00:00:00 [migration/1]" & @CRLF & _ "root 9 2 0 17:19 ? 00:00:00 [ksoftirqd/1]" & @CRLF & _ "root 10 2 0 17:19 ? 00:00:00 [watchdog/1]" & @CRLF & _ "root 11 2 0 17:19 ? 00:00:00 [events/0]" & @CRLF & _ "root 12 2 0 17:19 ? 00:00:00 [events/1]" & @CRLF & _ "root 13 2 0 17:19 ? 00:00:00 [cgroup]" & @CRLF & _ "root 14 2 0 17:19 ? 00:00:00 [khelper]" & @CRLF & _ "root 15 2 0 17:19 ? 00:00:00 [netns]" & @CRLF & _ "root 16 2 0 17:19 ? 00:00:00 [async/mgr]" & @CRLF & _ "root 17 2 0 17:19 ? 00:00:00 [pm]" & @CRLF & _ "root 18 2 0 17:19 ? 00:00:00 [sync_supers]" & @CRLF & _ "root 19 2 0 17:19 ? 00:00:00 [bdi-default]" & @CRLF & _ "root 20 2 0 17:19 ? 00:00:00 [kintegrityd/0]" & @CRLF & _ "root 21 2 0 17:19 ? 00:00:00 [kintegrityd/1]" & @CRLF & _ "root 22 2 0 17:19 ? 00:00:00 [kblockd/0]" & @CRLF & _ "root 23 2 0 17:19 ? 00:00:00 [kblockd/1]" & @CRLF & _ "root 24 2 0 17:19 ? 00:00:00 [kacpid]" & @CRLF & _ "root 25 2 0 17:19 ? 00:00:00 [kacpi_notify]" & @CRLF & _ "root 26 2 0 17:19 ? 00:00:00 [kacpi_hotplug]" & @CRLF & _ "root 27 2 0 17:19 ? 00:00:00 [ata_aux]" & @CRLF & _ "root 28 2 0 17:19 ? 00:00:00 [ata_sff/0]" & @CRLF & _ "root 29 2 0 17:19 ? 00:00:00 [ata_sff/1]" & @CRLF & _ "root 30 2 0 17:19 ? 00:00:00 [ksuspend_usbd]" & @CRLF & _ "root 31 2 0 17:19 ? 00:00:00 [khubd]" & @CRLF & _ "root 32 2 0 17:19 ? 00:00:00 [kseriod]" & @CRLF & _ "root 33 2 0 17:19 ? 00:00:00 [md/0]" & @CRLF & _ "root 34 2 0 17:19 ? 00:00:00 [md/1]" & @CRLF & _ "root 35 2 0 17:19 ? 00:00:00 [md_misc/0]" & @CRLF & _ "root 36 2 0 17:19 ? 00:00:00 [md_misc/1]" & @CRLF & _ "root 37 2 0 17:19 ? 00:00:00 [linkwatch]" & @CRLF & _ "root 38 2 0 17:19 ? 00:00:00 [khungtaskd]" & @CRLF & _ "root 39 2 0 17:19 ? 00:00:00 [kswapd0]" & @CRLF & _ "root 40 2 0 17:19 ? 00:00:00 [ksmd]" & @CRLF & _ "root 41 2 0 17:19 ? 00:00:00 [khugepaged]" & @CRLF & _ "root 42 2 0 17:19 ? 00:00:00 [aio/0]" & @CRLF & _ "root 43 2 0 17:19 ? 00:00:00 [aio/1]" & @CRLF & _ "root 44 2 0 17:19 ? 00:00:00 [crypto/0]" & @CRLF & _ "root 45 2 0 17:19 ? 00:00:00 [crypto/1]" & @CRLF & _ "root 50 2 0 17:19 ? 00:00:00 [kthrotld/0]" & @CRLF & _ "root 51 2 0 17:19 ? 00:00:00 [kthrotld/1]" & @CRLF & _ "root 53 2 0 17:19 ? 00:00:00 [kpsmoused]" & @CRLF & _ "root 54 2 0 17:19 ? 00:00:00 [usbhid_resumer]" & @CRLF & _ "root 85 2 0 17:19 ? 00:00:00 [kstriped]" & @CRLF & _ "root 153 2 0 17:19 ? 00:00:00 [scsi_eh_0]" & @CRLF & _ "root 154 2 0 17:19 ? 00:00:00 [scsi_eh_1]" & @CRLF & _ "root 171 2 0 17:19 ? 00:00:00 [scsi_eh_2]" & @CRLF & _ "root 250 2 0 17:19 ? 00:00:00 [kdmflush]" & @CRLF & _ "root 251 2 0 17:19 ? 00:00:00 [kdmflush]" & @CRLF & _ "root 269 2 0 17:19 ? 00:00:00 [jbd2/dm-0-8]" & @CRLF & _ "root 270 2 0 17:19 ? 00:00:00 [ext4-dio-unwrit]" & @CRLF & _ "root 366 1 0 17:19 ? 00:00:00 /sbin/udevd -d" & @CRLF & _ "root 898 2 0 17:19 ? 00:00:00 [jbd2/sda1-8]" & @CRLF & _ "root 899 2 0 17:19 ? 00:00:00 [ext4-dio-unwrit]" & @CRLF & _ "root 910 2 0 17:19 ? 00:00:00 [flush-253:0]" & @CRLF & _ "root 951 2 0 17:19 ? 00:00:00 [kauditd]" & @CRLF & _ "root 1017 1 0 17:19 ? 00:00:00 auditd" & @CRLF & _ "root 1042 1 0 17:19 ? 00:00:00 /sbin/rsyslogd -i /var/run/syslogd.pid -c 5" & @CRLF & _ "root 1071 1 0 17:19 ? 00:00:00 irqbalance --pid=/var/run/irqbalance.pid" & @CRLF & _ "rpc 1091 1 0 17:19 ? 00:00:00 rpcbind" & @CRLF & _ "root 1205 1 0 17:19 ? 00:00:00 lldpad -d" & @CRLF & _ "root 1214 2 0 17:19 ? 00:00:00 [scsi_tgtd/0]" & @CRLF & _ "root 1215 2 0 17:19 ? 00:00:00 [scsi_tgtd/1]" & @CRLF & _ "root 1222 2 0 17:19 ? 00:00:00 [fc_exch_workque]" & @CRLF & _ "root 1223 2 0 17:19 ? 00:00:00 [fc_rport_eq]" & @CRLF & _ "root 1226 2 0 17:19 ? 00:00:00 [fcoe_work/0]" & @CRLF & _ "root 1227 2 0 17:19 ? 00:00:00 [fcoe_work/1]" & @CRLF & _ "root 1228 2 0 17:19 ? 00:00:00 [fcoethread/0]" & @CRLF & _ "root 1229 2 0 17:19 ? 00:00:00 [fcoethread/1]" & @CRLF & _ "root 1230 2 0 17:19 ? 00:00:00 [cnic_wq]" & @CRLF & _ "root 1231 2 0 17:19 ? 00:00:00 [bnx2fc]" & @CRLF & _ "root 1232 2 0 17:19 ? 00:00:00 [bnx2fc_l2_threa]" & @CRLF & _ "root 1233 2 0 17:19 ? 00:00:00 [bnx2fc_thread/0]" & @CRLF & _ "root 1234 2 0 17:19 ? 00:00:00 [bnx2fc_thread/1]" & @CRLF & _ "root 1237 1 0 17:19 ? 00:00:00 /usr/sbin/fcoemon --syslog" & @CRLF & _ "dbus 1249 1 0 17:19 ? 00:00:00 dbus-daemon --system" & @CRLF & _ "root 1260 1 0 17:19 ? 00:00:00 NetworkManager --pid-file=/var/run/NetworkManager/NetworkManager.pid" & @CRLF & _ "root 1267 1 0 17:19 ? 00:00:00 /usr/sbin/modem-manager" & @CRLF & _ "root 1270 1260 0 17:19 ? 00:00:00 /sbin/dhclient -d -4 -sf /usr/libexec/nm-dhcp-client.action -pf /var/run/dhclient-eth1.pid -lf /var/lib/dhclient/dhclient-6f1cf570-d907" & @CRLF & _ "root 1279 1 0 17:19 ? 00:00:00 /usr/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -B -u -f /var/log/wpa_supplicant.log -P /var/run/wpa_supplicant.pid" & @CRLF & _ "rpcuser 1285 1 0 17:19 ? 00:00:00 rpc.statd" & @CRLF & _ "root 1319 1 0 17:19 ? 00:00:00 cupsd -C /etc/cups/cupsd.conf" & @CRLF & _ "root 1391 1 0 17:19 ? 00:00:00 /usr/sbin/acpid" & @CRLF & _ "68 1413 1 0 17:19 ? 00:00:00 hald" & @CRLF & _ "root 1414 1413 0 17:19 ? 00:00:00 hald-runner" & @CRLF & _ "root 1467 1414 0 17:19 ? 00:00:00 hald-addon-input: Listening on /dev/input/event3 /dev/input/event5 /dev/input/event1 /dev/input/event0" & @CRLF & _ "root 1468 1414 0 17:19 ? 00:00:00 hald-addon-storage: polling /dev/sr0 (every 2 sec)" & @CRLF & _ "68 1471 1414 0 17:19 ? 00:00:00 hald-addon-acpi: listening on acpid socket /var/run/acpid.socket" & @CRLF & _ "root 1493 1 0 17:19 ? 00:00:00 pcscd" & @CRLF & _ "root 1509 1 0 17:19 ? 00:00:00 automount --pid-file /var/run/autofs.pid" & @CRLF & _ "root 1586 1 0 17:19 ? 00:00:00 /usr/sbin/sshd" & @CRLF & _ "ntp 1594 1 0 17:19 ? 00:00:00 ntpd -u ntp:ntp -p /var/run/ntpd.pid -g" & @CRLF & _ "root 1698 1 0 17:19 ? 00:00:00 /usr/libexec/postfix/master" & @CRLF & _ "postfix 1703 1698 0 17:19 ? 00:00:00 qmgr -l -t fifo -u" & @CRLF & _ "root 1722 1 0 17:19 ? 00:00:00 /usr/sbin/abrtd" & @CRLF & _ "root 1730 1 0 17:19 ? 00:00:00 abrt-dump-oops -d /var/spool/abrt -rwx /var/log/messages" & @CRLF & _ "root 1738 1 0 17:19 ? 00:00:00 crond" & @CRLF & _ "root 1749 1 0 17:19 ? 00:00:00 /usr/sbin/atd" & @CRLF & _ "root 1776 1 0 17:19 ? 00:00:00 /usr/sbin/certmonger -S -p /var/run/certmonger.pid" & @CRLF & _ "strs 1823 1 0 17:19 ? 00:00:00 /opt/strs/bin_strs550/platform/ManagementGateway -managementroot /opt/strs/root_550_1821 -managementport 28000 -env file://.environment" & @CRLF & _ "root 1841 1 0 17:19 ? 00:00:00 login -- root" & @CRLF & _ "root 1843 1 0 17:19 tty2 00:00:00 /sbin/mingetty /dev/tty2" & @CRLF & _ "root 1847 1 0 17:19 tty3 00:00:00 /sbin/mingetty /dev/tty3" & @CRLF & _ "root 1849 1 0 17:19 tty4 00:00:00 /sbin/mingetty /dev/tty4" & @CRLF & _ "strs 1852 1 0 17:19 ? 00:00:00 /opt/strs/bin_strs561/platform/ManagementGateway -managementroot /opt/strs/root_561_228 -managementport 28200 -env file://.environment_" & @CRLF & _ "root 1855 1 0 17:19 tty5 00:00:00 /sbin/mingetty /dev/tty5" & @CRLF & _ "root 1857 1 0 17:19 tty6 00:00:00 /sbin/mingetty /dev/tty6" & @CRLF & _ "root 1865 366 0 17:19 ? 00:00:00 /sbin/udevd -d" & @CRLF & _ "root 1866 366 0 17:19 ? 00:00:00 /sbin/udevd -d" & @CRLF & _ "strs 1922 1 0 17:19 ? 00:00:00 /opt/strs/bin_strs550/platform/ManagementNanny -managementroot /opt/strs/root_550_1821 -managementport 28000 -env file://.environment_5" & @CRLF & _ "strs 2023 1 0 17:20 ? 00:00:00 /opt/strs/bin_strs561/platform/ManagementNanny -managementroot /opt/strs/root_561_228 -managementport 28200 -env file://.environment_5_" & @CRLF & _ "root 2039 1 0 17:20 ? 00:00:00 /usr/sbin/console-kit-daemon --no-daemon" & @CRLF & _ "root 2106 1841 0 17:20 tty1 00:00:00 -bash" & @CRLF & _ "root 2132 1586 0 17:20 ? 00:00:00 sshd: strs [priv]" & @CRLF & _ "strs 2136 2132 0 17:21 ? 00:00:00 sshd: strs@pts/0" & @CRLF & _ "strs 2137 2136 0 17:21 pts/0 00:00:00 -bash" & @CRLF & _ "postfix 2171 1698 0 17:23 ? 00:00:00 pickup -l -t fifo -u" & @CRLF & _ "strs 2189 2137 0 17:27 pts/0 00:00:00 ps -ef" & @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