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

/
/
s

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 = "(?s)(?:(?:ok|changed|fatal): \[)([A-Za-z0-9-.]+)(?:\]) => {\s+"msg": \[(.*?)\]\s+}" Local $sString = "PLAY [Core Switch] *************************************************************" & @CRLF & _ "" & @CRLF & _ "TASK [Mapping additional variables] ********************************************" & @CRLF & _ "ok: [acm-lab-core1.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [Setting the core number] *************************************************" & @CRLF & _ "ok: [acm-lab-core1.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [Create directory for configuration files] ********************************" & @CRLF & _ "ok: [acm-lab-core1.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [Render the trunk configuration] ******************************************" & @CRLF & _ "ok: [acm-lab-core1.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [Render the rollback configuration] ***************************************" & @CRLF & _ "ok: [acm-lab-core1.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [register the configuration rendered to a variable3] **********************" & @CRLF & _ "changed: [acm-lab-core1.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [debug] *******************************************************************" & @CRLF & _ "ok: [acm-lab-core1.expedient.com] => {" & @CRLF & _ " "msg": [" & @CRLF & _ " "interfaces {", " & @CRLF & _ " " ae10 {", " & @CRLF & _ " " unit 1001 {", " & @CRLF & _ " " encapsulation vlan-bridge;", " & @CRLF & _ " " vlan-id 1001;", " & @CRLF & _ " " }", " & @CRLF & _ " " unit 1002 {", " & @CRLF & _ " " encapsulation vlan-vpls;", " & @CRLF & _ " " vlan-id 1002;", " & @CRLF & _ " " }", " & @CRLF & _ " " }", " & @CRLF & _ " " irb {", " & @CRLF & _ " " unit 1001 {", " & @CRLF & _ " " description \\\\\"PUBLIC: Dunder Mifflin\\\\(/)\";", " & @CRLF & _ " " family inet {", " & @CRLF & _ " " address 206.166.155.2/29 {", " & @CRLF & _ " " vrrp-group 1001 {", " & @CRLF & _ " " virtual-address 206.166.155.1;", " & @CRLF & _ " " priority 200;", " & @CRLF & _ " " fast-interval 500;", " & @CRLF & _ " " no-preempt;", " & @CRLF & _ " " accept-data;", " & @CRLF & _ " " }", " & @CRLF & _ " " } ", " & @CRLF & _ " " }", " & @CRLF & _ " " }", " & @CRLF & _ " " } ", " & @CRLF & _ " "}", " & @CRLF & _ " "bridge-domains {", " & @CRLF & _ " " VLAN1001 {", " & @CRLF & _ " " vlan-id 1001;", " & @CRLF & _ " " interface ae10.1001;", " & @CRLF & _ " " routing-interface irb.1001;", " & @CRLF & _ " " }", " & @CRLF & _ " "}", " & @CRLF & _ " "routing-instances {", " & @CRLF & _ " " VPLS1002 {", " & @CRLF & _ " " instance-type vpls;", " & @CRLF & _ " " vlan-id 1002;", " & @CRLF & _ " " interface ae10.1002;", " & @CRLF & _ " " protocols {", " & @CRLF & _ " " vpls {", " & @CRLF & _ " " encapsulation-type ethernet-vlan;", " & @CRLF & _ " " interface ae10.1002;", " & @CRLF & _ " " no-tunnel-services;vpls-id 1062310;mtu 9216;", " & @CRLF & _ " " neighbor 206.210.84.1;", " & @CRLF & _ " " }", " & @CRLF & _ " " }", " & @CRLF & _ " " }", " & @CRLF & _ " "}", " & @CRLF & _ " "protocols {", " & @CRLF & _ " " bgp {", " & @CRLF & _ " " group DunderMiff-vsrx {", " & @CRLF & _ " " type external;", " & @CRLF & _ " " import [ tag-vsrx DunderMiff-in ];", " & @CRLF & _ " " export default-only;", " & @CRLF & _ " " peer-as 64512;", " & @CRLF & _ " " neighbor 206.166.155.5;", " & @CRLF & _ " " }", " & @CRLF & _ " " }", " & @CRLF & _ " "}", " & @CRLF & _ " "policy-options {", " & @CRLF & _ " " policy-statement DunderMiff-in {", " & @CRLF & _ " " term customer-networks { ", " & @CRLF & _ " " from {", " & @CRLF & _ " " route-filter 2.2.1.0/24 exact;", " & @CRLF & _ " " route-filter 2.2.1.0/24 exact;", " & @CRLF & _ " " } ", " & @CRLF & _ " " then accept; ", " & @CRLF & _ " " } ", " & @CRLF & _ " " term deny { ", " & @CRLF & _ " " then reject; ", " & @CRLF & _ " " } ", " & @CRLF & _ " " } ", " & @CRLF & _ " "}"" & @CRLF & _ " ]" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "PLAY [Core Switch] *************************************************************" & @CRLF & _ "" & @CRLF & _ "TASK [Mapping additional variables] ********************************************" & @CRLF & _ "ok: [acm-lab-core2.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [Setting the core number] *************************************************" & @CRLF & _ "ok: [acm-lab-core2.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [Create directory for configuration files] ********************************" & @CRLF & _ "ok: [acm-lab-core2.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [Render the trunk configuration] ******************************************" & @CRLF & _ "ok: [acm-lab-core2.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [Render the rollback configuration] ***************************************" & @CRLF & _ "ok: [acm-lab-core2.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [register the configuration rendered to a variable3] **********************" & @CRLF & _ "changed: [acm-lab-core2.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [debug] *******************************************************************" & @CRLF & _ "ok: [acm-lab-core2.expedient.com] => {" & @CRLF & _ " "msg": [" & @CRLF & _ " "interfaces {", " & @CRLF & _ " " ae10 {", " & @CRLF & _ " " unit 1001 {", " & @CRLF & _ " " encapsulation vlan-bridge;", " & @CRLF & _ " " vlan-id 1001;", " & @CRLF & _ " " }", " & @CRLF & _ " " unit 1002 {", " & @CRLF & _ " " encapsulation vlan-vpls;", " & @CRLF & _ " " vlan-id 1002;", " & @CRLF & _ " " }", " & @CRLF & _ " " }", " & @CRLF & _ " " irb {", " & @CRLF & _ " " unit 1001 {", " & @CRLF & _ " " description \\\\\"PUBLIC: Dunder Mifflin\\\\(/)\";", " & @CRLF & _ " " family inet {", " & @CRLF & _ " " address 206.166.155.3/29 {", " & @CRLF & _ " " vrrp-group 1001 {", " & @CRLF & _ " " virtual-address 206.166.155.1;", " & @CRLF & _ " " priority 100;", " & @CRLF & _ " " fast-interval 500;", " & @CRLF & _ " " no-preempt;", " & @CRLF & _ " " accept-data;", " & @CRLF & _ " " }", " & @CRLF & _ " " } ", " & @CRLF & _ " " }", " & @CRLF & _ " " }", " & @CRLF & _ " " } ", " & @CRLF & _ " "}", " & @CRLF & _ " "bridge-domains {", " & @CRLF & _ " " VLAN1001 {", " & @CRLF & _ " " vlan-id 1001;", " & @CRLF & _ " " interface ae10.1001;", " & @CRLF & _ " " routing-interface irb.1001;", " & @CRLF & _ " " }", " & @CRLF & _ " "}", " & @CRLF & _ " "routing-instances {", " & @CRLF & _ " " VPLS1002 {", " & @CRLF & _ " " instance-type vpls;", " & @CRLF & _ " " vlan-id 1002;", " & @CRLF & _ " " interface ae10.1002;", " & @CRLF & _ " " protocols {", " & @CRLF & _ " " vpls {", " & @CRLF & _ " " encapsulation-type ethernet-vlan;", " & @CRLF & _ " " interface ae10.1002;", " & @CRLF & _ " " no-tunnel-services;vpls-id 1062310;mtu 9216;", " & @CRLF & _ " " neighbor 206.210.84.1;", " & @CRLF & _ " " }", " & @CRLF & _ " " }", " & @CRLF & _ " " }", " & @CRLF & _ " "}", " & @CRLF & _ " "protocols {", " & @CRLF & _ " " bgp {", " & @CRLF & _ " " group DunderMiff-vsrx {", " & @CRLF & _ " " type external;", " & @CRLF & _ " " import [ tag-vsrx DunderMiff-in ];", " & @CRLF & _ " " export default-only;", " & @CRLF & _ " " peer-as 64512;", " & @CRLF & _ " " neighbor 206.166.155.5;", " & @CRLF & _ " " }", " & @CRLF & _ " " }", " & @CRLF & _ " "}", " & @CRLF & _ " "policy-options {", " & @CRLF & _ " " policy-statement DunderMiff-in {", " & @CRLF & _ " " term customer-networks { ", " & @CRLF & _ " " from {", " & @CRLF & _ " " route-filter 2.2.1.0/24 exact;", " & @CRLF & _ " " route-filter 2.2.1.0/24 exact;", " & @CRLF & _ " " } ", " & @CRLF & _ " " then accept; ", " & @CRLF & _ " " } ", " & @CRLF & _ " " term deny { ", " & @CRLF & _ " " then reject; ", " & @CRLF & _ " " } ", " & @CRLF & _ " " } ", " & @CRLF & _ " "}"" & @CRLF & _ " ]" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "PLAY [Spine Switch] ************************************************************" & @CRLF & _ "" & @CRLF & _ "TASK [Mapping additional variables] ********************************************" & @CRLF & _ "ok: [acm-lab-spine1.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [Render the trunk configuration] ******************************************" & @CRLF & _ "ok: [acm-lab-spine1.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [Render the rollback configuration] ***************************************" & @CRLF & _ "ok: [acm-lab-spine1.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [Display the configuration rendered] **************************************" & @CRLF & _ "changed: [acm-lab-spine1.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [debug] *******************************************************************" & @CRLF & _ "ok: [acm-lab-spine1.expedient.com] => {" & @CRLF & _ " "msg": [" & @CRLF & _ " "interfaces {", " & @CRLF & _ " " ae0 {", " & @CRLF & _ " " unit 1001 {", " & @CRLF & _ " " vlan-id 1001;", " & @CRLF & _ " " }", " & @CRLF & _ " " unit 1002 {", " & @CRLF & _ " " vlan-id 1002;", " & @CRLF & _ " " } ", " & @CRLF & _ " " }", " & @CRLF & _ " " ae1 {", " & @CRLF & _ " " unit 1001 {", " & @CRLF & _ " " vlan-id 1001;", " & @CRLF & _ " " }", " & @CRLF & _ " " unit 1002 {", " & @CRLF & _ " " vlan-id 1002;", " & @CRLF & _ " " }", " & @CRLF & _ " " }", " & @CRLF & _ " "}", " & @CRLF & _ " "vlans {", " & @CRLF & _ " " VLAN1001 {", " & @CRLF & _ " " vlan-id 1001;", " & @CRLF & _ " " interface ae0.1001;", " & @CRLF & _ " " interface ae1.1001;", " & @CRLF & _ " " }", " & @CRLF & _ " " VLAN1002 {", " & @CRLF & _ " " vlan-id 1002;", " & @CRLF & _ " " interface ae0.1002;", " & @CRLF & _ " " interface ae1.1002;", " & @CRLF & _ " " } ", " & @CRLF & _ " "}"" & @CRLF & _ " ]" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "TASK [No Deploy] ***************************************************************" & @CRLF & _ "skipping: [acm-lab-spine1.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [debug] *******************************************************************" & @CRLF & _ "skipping: [acm-lab-spine1.expedient.com]" & @CRLF & _ "" & @CRLF & _ "PLAY [POD Switch] **************************************************************" & @CRLF & _ "" & @CRLF & _ "TASK [Setting the interface range] *********************************************" & @CRLF & _ "ok: [acm-lab-pod1-sw.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [Mapping additional variables] ********************************************" & @CRLF & _ "ok: [acm-lab-pod1-sw.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [Render the trunk configuration] ******************************************" & @CRLF & _ "ok: [acm-lab-pod1-sw.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [Render the rollback configuration] ***************************************" & @CRLF & _ "ok: [acm-lab-pod1-sw.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [Display the configuration rendered] **************************************" & @CRLF & _ "changed: [acm-lab-pod1-sw.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [debug] *******************************************************************" & @CRLF & _ "ok: [acm-lab-pod1-sw.expedient.com] => {" & @CRLF & _ " "msg": [" & @CRLF & _ " "interfaces {", " & @CRLF & _ " " interface-range DVS {", " & @CRLF & _ " " unit 0 {", " & @CRLF & _ " " family ethernet-switching {", " & @CRLF & _ " " vlan {", " & @CRLF & _ " " members 1001;", " & @CRLF & _ " " members 1002;", " & @CRLF & _ " " members 1111;", " & @CRLF & _ " " }", " & @CRLF & _ " " }", " & @CRLF & _ " " }", " & @CRLF & _ " " } ", " & @CRLF & _ " " ae0 {", " & @CRLF & _ " " unit 1001 {", " & @CRLF & _ " " vlan-id 1001;", " & @CRLF & _ " " }", " & @CRLF & _ " " unit 1002 {", " & @CRLF & _ " " vlan-id 1002;", " & @CRLF & _ " " } ", " & @CRLF & _ " " }", " & @CRLF & _ " "}", " & @CRLF & _ " "vlans {", " & @CRLF & _ " " VLAN1001 {", " & @CRLF & _ " " vlan-id 1001;", " & @CRLF & _ " " interface ae0.1001;", " & @CRLF & _ " " }", " & @CRLF & _ " " VLAN1002 {", " & @CRLF & _ " " vlan-id 1002;", " & @CRLF & _ " " interface ae0.1002;", " & @CRLF & _ " " }", " & @CRLF & _ " " VLAN1111 {", " & @CRLF & _ " " vlan-id 1111;", " & @CRLF & _ " " }", " & @CRLF & _ " "}"" & @CRLF & _ " ]" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "PLAY [151-fw - Radius Authentication] ******************************************" & @CRLF & _ "" & @CRLF & _ "TASK [Setting the interface range] *********************************************" & @CRLF & _ "ok: [151-fw-mgmt.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [Mapping additional variables] ********************************************" & @CRLF & _ "ok: [151-fw-mgmt.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [Render the trunk configuration] ******************************************" & @CRLF & _ "changed: [151-fw-mgmt.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [Render the rollback configuration] ***************************************" & @CRLF & _ "changed: [151-fw-mgmt.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [Display the configuration rendered] **************************************" & @CRLF & _ "changed: [151-fw-mgmt.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [debug] *******************************************************************" & @CRLF & _ "ok: [151-fw-mgmt.expedient.com] => {" & @CRLF & _ " "msg": [" & @CRLF & _ " "security {", " & @CRLF & _ " " zones {", " & @CRLF & _ " " security-zone untrust {", " & @CRLF & _ " " address-book {", " & @CRLF & _ " " address dunderhead-vsrx 1.1.1.1/32;", " & @CRLF & _ " " address-set CUSTCBB-Auth-Expedient-Managed-Customer-FW {", " & @CRLF & _ " " address dunderhead-vsrx;", " & @CRLF & _ " " }", " & @CRLF & _ " " }", " & @CRLF & _ " " }", " & @CRLF & _ " " }", " & @CRLF & _ " "}"" & @CRLF & _ " ]" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "PLAY [tdp-fw - Radius Authentication] ******************************************" & @CRLF & _ "" & @CRLF & _ "TASK [Setting the interface range] *********************************************" & @CRLF & _ "ok: [tdp-fw-mgmt.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [Mapping additional variables] ********************************************" & @CRLF & _ "ok: [tdp-fw-mgmt.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [Render the trunk configuration] ******************************************" & @CRLF & _ "changed: [tdp-fw-mgmt.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [Render the rollback configuration] ***************************************" & @CRLF & _ "changed: [tdp-fw-mgmt.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [Display the configuration rendered] **************************************" & @CRLF & _ "changed: [tdp-fw-mgmt.expedient.com]" & @CRLF & _ "" & @CRLF & _ "TASK [debug] *******************************************************************" & @CRLF & _ "ok: [tdp-fw-mgmt.expedient.com] => {" & @CRLF & _ " "msg": [" & @CRLF & _ " "security {", " & @CRLF & _ " " zones {", " & @CRLF & _ " " security-zone untrust {", " & @CRLF & _ " " address-book {", " & @CRLF & _ " " address dunderhead-vsrx 1.1.1.1/32;", " & @CRLF & _ " " address-set CUSTCBB-Auth-Expedient-Managed-Customer-FW {", " & @CRLF & _ " " address dunderhead-vsrx;", " & @CRLF & _ " " }", " & @CRLF & _ " " }", " & @CRLF & _ " " }", " & @CRLF & _ " " }", " & @CRLF & _ " "}"" & @CRLF & _ " ]" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "PLAY RECAP *********************************************************************" & @CRLF & _ "151-fw-mgmt.expedient.com : ok=6 changed=3 unreachable=0 failed=0 " & @CRLF & _ "acm-lab-core1.expedient.com : ok=7 changed=1 unreachable=0 failed=0 " & @CRLF & _ "acm-lab-core2.expedient.com : ok=7 changed=1 unreachable=0 failed=0 " & @CRLF & _ "acm-lab-pod1-sw.expedient.com : ok=6 changed=1 unreachable=0 failed=0 " & @CRLF & _ "acm-lab-spine1.expedient.com : ok=5 changed=1 unreachable=0 failed=0 " & @CRLF & _ "tdp-fw-mgmt.expedient.com : ok=6 changed=3 unreachable=0 failed=0 " Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYFULLMATCH) ; 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