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)^(?P<ip>\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}) - - \[(?P<date>.*)\] "(?P<request>.*?)" (?P<status>\d*) (?P<size>\d*) "(?P<referer>.*?)" "(?P<user_agent>.*?)".*$" Local $sString = "192.0.102.40 - - [09/Apr/2018:06:26:33 -0400] "HEAD /blog HTTP/1.1" 301 0 "-" "jetmon/1.0 (Jetpack Site Uptime Monitor by WordPress.com)"" & @CRLF & _ "192.0.102.40 - - [09/Apr/2018:06:26:33 -0400] "HEAD /blog HTTP/1.1" 301 0 "-" "jetmon/1.0 (Jetpack Site Uptime Monitor by WordPress.com)"" & @CRLF & _ "198.199.64.224 - - [09/Apr/2018:06:26:33 -0400] "POST /blog/wp-cron.php?doing_wp_cron=1523269593.5797910690307617187500 HTTP/1.1" 499 0 "-" "WordPress/4.9.5; https://ivoah.net/blog"" & @CRLF & _ "192.0.102.40 - - [09/Apr/2018:06:26:33 -0400] "HEAD /blog/ HTTP/1.1" 200 0 "-" "jetmon/1.0 (Jetpack Site Uptime Monitor by WordPress.com)"" & @CRLF & _ "192.0.102.40 - - [09/Apr/2018:06:31:32 -0400] "HEAD /blog HTTP/1.1" 301 0 "-" "jetmon/1.0 (Jetpack Site Uptime Monitor by WordPress.com)"" & @CRLF & _ "192.0.102.40 - - [09/Apr/2018:06:31:32 -0400] "HEAD /blog HTTP/1.1" 301 0 "-" "jetmon/1.0 (Jetpack Site Uptime Monitor by WordPress.com)"" & @CRLF & _ "198.199.64.224 - - [09/Apr/2018:06:31:33 -0400] "POST /blog/wp-cron.php?doing_wp_cron=1523269893.1204290390014648437500 HTTP/1.1" 499 0 "-" "WordPress/4.9.5; https://ivoah.net/blog"" & @CRLF & _ "192.0.102.40 - - [09/Apr/2018:06:31:33 -0400] "HEAD /blog/ HTTP/1.1" 200 0 "-" "jetmon/1.0 (Jetpack Site Uptime Monitor by WordPress.com)"" & @CRLF & _ "192.0.102.40 - - [09/Apr/2018:06:36:39 -0400] "HEAD /blog HTTP/1.1" 301 0 "-" "jetmon/1.0 (Jetpack Site Uptime Monitor by WordPress.com)"" & @CRLF & _ "192.0.102.40 - - [09/Apr/2018:06:36:39 -0400] "HEAD /blog HTTP/1.1" 301 0 "-" "jetmon/1.0 (Jetpack Site Uptime Monitor by WordPress.com)"" & @CRLF & _ "198.199.64.224 - - [09/Apr/2018:06:36:39 -0400] "POST /blog/wp-cron.php?doing_wp_cron=1523270199.4308791160583496093750 HTTP/1.1" 499 0 "-" "WordPress/4.9.5; https://ivoah.net/blog"" & @CRLF & _ "192.0.102.40 - - [09/Apr/2018:06:36:39 -0400] "HEAD /blog/ HTTP/1.1" 200 0 "-" "jetmon/1.0 (Jetpack Site Uptime Monitor by WordPress.com)"" & @CRLF & _ "47.52.68.60 - - [09/Apr/2018:06:37:08 -0400] "POST /blog/2016/05/13/mate-on-raspberry-pi/?share=email&nb=1 HTTP/1.1" 302 5 "https://ivoah.net/blog/2016/05/13/mate-on-raspberry-pi/?share=email&nb=1" "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2)"" & @CRLF & _ "47.52.68.60 - - [09/Apr/2018:06:37:09 -0400] "GET /blog/2016/05/13/mate-on-raspberry-pi/?shared=email HTTP/1.1" 200 30602 "https://ivoah.net/blog/2016/05/13/mate-on-raspberry-pi/?share=email&nb=1" "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2)"" & @CRLF & _ "94.23.33.67 - - [09/Apr/2018:06:37:43 -0400] "GET //wp-content/plugins/cherry-plugin/admin/css/cherry-admin-plugin.css HTTP/1.0" 301 184 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36"" & @CRLF & _ "94.23.33.67 - - [09/Apr/2018:06:37:43 -0400] "GET //wp-content/plugins/cherry-plugin/admin/css/cherry-admin-plugin.css HTTP/1.0" 301 184 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36"" & @CRLF & _ "94.23.33.67 - - [09/Apr/2018:06:37:44 -0400] "GET //wp-content/plugins/cherry-plugin/admin/css/cherry-admin-plugin.css HTTP/1.0" 404 570 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36"" & @CRLF & _ "94.23.33.67 - - [09/Apr/2018:06:37:44 -0400] "GET //wp-content/plugins/cherry-plugin/admin/css/cherry-admin-plugin.css HTTP/1.0" 301 184 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36"" & @CRLF & _ "94.23.33.67 - - [09/Apr/2018:06:37:45 -0400] "GET //wp-content/plugins/cherry-plugin/admin/css/cherry-admin-plugin.css HTTP/1.0" 301 184 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36"" & @CRLF & _ "94.23.33.67 - - [09/Apr/2018:06:37:45 -0400] "GET //wp-content/plugins/cherry-plugin/admin/css/cherry-admin-plugin.css HTTP/1.0" 404 570 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36"" & @CRLF & _ "192.0.102.40 - - [09/Apr/2018:06:41:44 -0400] "HEAD /blog HTTP/1.1" 301 0 "-" "jetmon/1.0 (Jetpack Site Uptime Monitor by WordPress.com)"" & @CRLF & _ "192.0.102.40 - - [09/Apr/2018:06:41:44 -0400] "HEAD /blog HTTP/1.1" 301 0 "-" "jetmon/1.0 (Jetpack Site Uptime Monitor by WordPress.com)"" & @CRLF & _ "198.199.64.224 - - [09/Apr/2018:06:41:44 -0400] "POST /blog/wp-cron.php?doing_wp_cron=1523270504.8351509571075439453125 HTTP/1.1" 499 0 "-" "WordPress/4.9.5; https://ivoah.net/blog"" & @CRLF & _ "192.0.102.40 - - [09/Apr/2018:06:41:44 -0400] "HEAD /blog/ HTTP/1.1" 200 0 "-" "jetmon/1.0 (Jetpack Site Uptime Monitor by WordPress.com)"" & @CRLF & _ "207.244.149.74 - - [09/Apr/2018:06:45:38 -0400] "GET /wp-content/plugins/wp-formgenerator/assets/js/simpleslider.js HTTP/1.1" 404 341 "https://ivoah.net/wp-content/plugins/wp-formgenerator/assets/js/simpleslider.js" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36"" & @CRLF & _ "54.36.148.188 - - [09/Apr/2018:06:45:44 -0400] "GET /wp/audio/05042011.m4a HTTP/1.1" 301 184 "-" "Mozilla/5.0 (compatible; AhrefsBot/5.2; +http://ahrefs.com/robot/)"" & @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