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

/
/
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)\!\ninterface\W[A-Z].*Ethernet(\d)\/(\d)([^\!]*)" Local $sString = "Building configuration..." & @CRLF & _ "" & @CRLF & _ "Current configuration : 3058 bytes" & @CRLF & _ "!" & @CRLF & _ "version 12.2" & @CRLF & _ "no service pad" & @CRLF & _ "service timestamps debug datetime msec" & @CRLF & _ "service timestamps log datetime msec" & @CRLF & _ "no service password-encryption" & @CRLF & _ "!" & @CRLF & _ "hostname cisco.test" & @CRLF & _ "!" & @CRLF & _ "boot-start-marker" & @CRLF & _ "boot-end-marker" & @CRLF & _ "!" & @CRLF & _ "!" & @CRLF & _ "username cisco password 0 cisco" & @CRLF & _ "!" & @CRLF & _ "!" & @CRLF & _ "aaa new-model" & @CRLF & _ "!" & @CRLF & _ "!" & @CRLF & _ "aaa authentication login default local enable" & @CRLF & _ "!" & @CRLF & _ "!" & @CRLF & _ "!" & @CRLF & _ "aaa session-id common" & @CRLF & _ "system mtu routing 1500" & @CRLF & _ "ip routing" & @CRLF & _ "no ip domain-lookup" & @CRLF & _ "ip domain-name cisco.test" & @CRLF & _ "ip dhcp excluded-address 172.29.1.200" & @CRLF & _ "ip dhcp excluded-address 172.29.1.1" & @CRLF & _ "!" & @CRLF & _ "ip dhcp pool USERS" & @CRLF & _ " network 172.29.1.0 255.255.255.0" & @CRLF & _ " default-router 172.29.1.1 " & @CRLF & _ "!" & @CRLF & _ "!" & @CRLF & _ "!" & @CRLF & _ "!" & @CRLF & _ "crypto pki trustpoint TP-self-signed-508261888" & @CRLF & _ " enrollment selfsigned" & @CRLF & _ " subject-name cn=IOS-Self-Signed-Certificate-508261888" & @CRLF & _ " revocation-check none" & @CRLF & _ " rsakeypair TP-self-signed-508261888" & @CRLF & _ "!" & @CRLF & _ "!" & @CRLF & _ "crypto pki certificate chain TP-self-signed-508261888" & @CRLF & _ " certificate self-signed 01" & @CRLF & _ " 3082023D 308201A6 A0030201 02020101 300D0609 2A864886 F70D0101 04050030 " & @CRLF & _ " 30312E30 2C060355 04031325 494F532D 53656C66 2D536967 6E65642D 43657274 " & @CRLF & _ " 69666963 6174652D 35303832 36313838 38301E17 0D393330 33303130 30303130 " & @CRLF & _ " 335A170D 32303031 30313030 30303030 5A303031 2E302C06 03550403 1325494F " & @CRLF & _ " 532D5365 6C662D53 69676E65 642D4365 72746966 69636174 652D3530 38323631 " & @CRLF & _ " 38383830 819F300D 06092A86 4886F70D 01010105 0003818D 00308189 02818100 " & @CRLF & _ " DAB963DF 1F90F0D1 0C422912 0788DC49 A3908659 CE3E9610 433233A5 1B1E00F5 " & @CRLF & _ " 3941C9E6 B9FC37C4 F1D39723 282E38FC E03A0384 9C386E0A 380FCE52 B77A1A69 " & @CRLF & _ " F62F2E8B FB570F83 3F0CDD21 058BE6BD A1B8BE37 4AFD3B02 E339CBA9 EB073555 " & @CRLF & _ " 63358466 8C7CFF88 D0F562CC B6C6CC0D 981CAB30 CB7CA2E5 CDD17A21 5AEC6F09 " & @CRLF & _ " 02030100 01A36730 65300F06 03551D13 0101FF04 05300301 01FF3012 0603551D " & @CRLF & _ " 11040B30 09820753 77697463 682E301F 0603551D 23041830 16801460 F6485305 " & @CRLF & _ " D274086D F29F51DE A3659656 752BB730 1D060355 1D0E0416 041460F6 485305D2 " & @CRLF & _ " 74086DF2 9F51DEA3 65965675 2BB7300D 06092A86 4886F70D 01010405 00038181 " & @CRLF & _ " 00590208 E0E292D7 B18ABD77 3D781313 A70B7896 46EE9079 1C66D967 B01D078C " & @CRLF & _ " A420A1D5 FE4C7CA9 EA89BC95 D0F2B0A4 4298B12C 3AB2DDC3 7608BD34 3FB41615 " & @CRLF & _ " 6833E4C3 52BDFDA2 DF7C4C9A B94A4745 386E8DB0 C4EB298A D5B00560 490EA5AF " & @CRLF & _ " 5B357860 E01D60F2 D9DBD62F 0922DF2B 11039A71 B23064EC CB4C846E DCCCDC4B A4" & @CRLF & _ " quit" & @CRLF & _ "!" & @CRLF & _ "!" & @CRLF & _ "!" & @CRLF & _ "spanning-tree mode pvst" & @CRLF & _ "spanning-tree extend system-id" & @CRLF & _ "!" & @CRLF & _ "vlan internal allocation policy ascending" & @CRLF & _ "!" & @CRLF & _ "ip ssh time-out 60" & @CRLF & _ "ip ssh authentication-retries 2" & @CRLF & _ "ip ssh version 2" & @CRLF & _ "!" & @CRLF & _ "!" & @CRLF & _ "interface FastEthernet0/1" & @CRLF & _ " switchport mode access" & @CRLF & _ " switchport port-security" & @CRLF & _ " switchport port-security mac-address sticky" & @CRLF & _ " shutdown" & @CRLF & _ "!" & @CRLF & _ "interface FastEthernet0/2" & @CRLF & _ "!" & @CRLF & _ "interface FastEthernet0/3" & @CRLF & _ "!" & @CRLF & _ "interface FastEthernet0/4" & @CRLF & _ "!" & @CRLF & _ "interface FastEthernet0/5" & @CRLF & _ "!" & @CRLF & _ "interface FastEthernet0/6" & @CRLF & _ "!" & @CRLF & _ "interface FastEthernet0/7" & @CRLF & _ "!" & @CRLF & _ "interface FastEthernet0/8" & @CRLF & _ "!" & @CRLF & _ "interface GigabitEthernet0/1" & @CRLF & _ "!" & @CRLF & _ "interface Vlan1" & @CRLF & _ " ip address 172.29.1.200 255.255.255.0" & @CRLF & _ "!" & @CRLF & _ "ip classless" & @CRLF & _ "ip http server" & @CRLF & _ "ip http secure-server" & @CRLF & _ "!" & @CRLF & _ "!" & @CRLF & _ "!" & @CRLF & _ "line con 0" & @CRLF & _ " length 0" & @CRLF & _ "line vty 0 4" & @CRLF & _ " privilege level 15" & @CRLF & _ " logging synchronous" & @CRLF & _ " length 0" & @CRLF & _ " transport input ssh" & @CRLF & _ "line vty 5 15" & @CRLF & _ " privilege level 15" & @CRLF & _ " logging synchronous" & @CRLF & _ " length 0" & @CRLF & _ " transport input ssh" & @CRLF & _ "!" & @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