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

/
/
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)^\s*(?<time>[^ ]* {1,2}[^ ]* [^ ]*) \[(?<pid>\d+)\] (?<macid>[\-\w]*)\s*(?<component>\w*):\s+(?<severity>\w+):\s+(?<action>\w+):\s+(?<action_status>\w+) (?<mesage>[^\(]*) (\((?<meta>.*)\))$" Local $sString = "Sep 19 09:23:01 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_request: Completed cib_modify operation for section nodes: OK (rc=0, origin=d2c-76-8a-ac-64-6e/crm_attribute/4, version=0.1352.0)" & @CRLF & _ "Sep 19 09:23:06 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_ping: Reporting our current digest to d2c-76-8a-ac-64-50: bc17de2aedf4d53c3f4fa8021fffd2b1 for 0.1352.0 (0xe2bf50 0)" & @CRLF & _ "Sep 19 09:30:53 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_request: Completed cib_modify operation for section nodes: OK (rc=0, origin=d2c-76-8a-ac-64-50/crm_attribute/4, version=0.1352.0)" & @CRLF & _ "Sep 19 09:30:58 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_ping: Reporting our current digest to d2c-76-8a-ac-64-50: bc17de2aedf4d53c3f4fa8021fffd2b1 for 0.1352.0 (0xe2e450 0)" & @CRLF & _ "Sep 19 09:37:59 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_request: Completed cib_modify operation for section nodes: OK (rc=0, origin=d2c-76-8a-ac-65-68/crm_attribute/4, version=0.1352.0)" & @CRLF & _ "Sep 19 09:38:04 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_ping: Reporting our current digest to d2c-76-8a-ac-64-50: bc17de2aedf4d53c3f4fa8021fffd2b1 for 0.1352.0 (0xe372d0 0)" & @CRLF & _ "Sep 19 09:43:25 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_request: Forwarding cib_modify operation for section nodes to master (origin=local/crm_attribute/4)" & @CRLF & _ "Sep 19 09:43:25 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_request: Completed cib_modify operation for section nodes: OK (rc=0, origin=d2c-76-8a-ac-64-6e/crm_attribute/4, version=0.1352.0)" & @CRLF & _ "Sep 19 09:43:30 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_ping: Reporting our current digest to d2c-76-8a-ac-64-50: bc17de2aedf4d53c3f4fa8021fffd2b1 for 0.1352.0 (0xe2be50 0)" & @CRLF & _ "Sep 19 09:46:55 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_request: Completed cib_modify operation for section nodes: OK (rc=0, origin=d2c-76-8a-ac-64-50/crm_attribute/4, version=0.1352.0)" & @CRLF & _ "Sep 19 09:47:00 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_ping: Reporting our current digest to d2c-76-8a-ac-64-50: bc17de2aedf4d53c3f4fa8021fffd2b1 for 0.1352.0 (0xeead20 0)" & @CRLF & _ "Sep 19 09:54:03 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_request: Completed cib_modify operation for section nodes: OK (rc=0, origin=d2c-76-8a-ac-65-68/crm_attribute/4, version=0.1352.0)" & @CRLF & _ "Sep 19 09:54:08 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_ping: Reporting our current digest to d2c-76-8a-ac-64-50: bc17de2aedf4d53c3f4fa8021fffd2b1 for 0.1352.0 (0x129d470 0)" & @CRLF & _ "Sep 19 10:02:51 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_request: Completed cib_modify operation for section nodes: OK (rc=0, origin=d2c-76-8a-ac-64-50/crm_attribute/4, version=0.1352.0)" & @CRLF & _ "Sep 19 10:02:56 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_ping: Reporting our current digest to d2c-76-8a-ac-64-50: bc17de2aedf4d53c3f4fa8021fffd2b1 for 0.1352.0 (0xe2e450 0)" & @CRLF & _ "Sep 19 10:03:38 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_request: Forwarding cib_modify operation for section nodes to master (origin=local/crm_attribute/4)" & @CRLF & _ "Sep 19 10:03:38 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_request: Completed cib_modify operation for section nodes: OK (rc=0, origin=d2c-76-8a-ac-64-6e/crm_attribute/4, version=0.1352.0)" & @CRLF & _ "Sep 19 10:03:43 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_ping: Reporting our current digest to d2c-76-8a-ac-64-50: bc17de2aedf4d53c3f4fa8021fffd2b1 for 0.1352.0 (0xb60f30 0)" & @CRLF & _ "Sep 19 10:10:11 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_request: Completed cib_modify operation for section nodes: OK (rc=0, origin=d2c-76-8a-ac-65-68/crm_attribute/4, version=0.1352.0)" & @CRLF & _ "Sep 19 10:10:16 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_ping: Reporting our current digest to d2c-76-8a-ac-64-50: bc17de2aedf4d53c3f4fa8021fffd2b1 for 0.1352.0 (0xd963e0 0)" & @CRLF & _ "Sep 19 10:18:44 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_request: Completed cib_modify operation for section nodes: OK (rc=0, origin=d2c-76-8a-ac-64-50/crm_attribute/4, version=0.1352.0)" & @CRLF & _ "Sep 19 10:18:49 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_ping: Reporting our current digest to d2c-76-8a-ac-64-50: bc17de2aedf4d53c3f4fa8021fffd2b1 for 0.1352.0 (0x129d4f0 0)" 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