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"
"
g

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 = "(VRP.+|Cisco\sIOS.+)(Version\s\S+)|(HUAWEI\s\S+|cisco\s\S+)" Local $sString = "<RMCOVTA0201>dis ver" & @CRLF & _ "Huawei Versatile Routing Platform Software" & @CRLF & _ "VRP (R) software, Version 8.10 (CX600 V800R007C10)" & @CRLF & _ "Copyright (C) 2012-2014 Huawei Technologies Co., Ltd." & @CRLF & _ "HUAWEI CX600-X2-M16 uptime is 902 days, 1 hour, 17 minutes " & @CRLF & _ "" & @CRLF & _ "CX600-X2-M16 version information:" & @CRLF & _ "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" & @CRLF & _ "BKP version information:" & @CRLF & _ " PCB Version : CX68BKP03B REV B" & @CRLF & _ " MPU Slot Quantity : 2" & @CRLF & _ " NPU Slot Quantity : 2" & @CRLF & _ " CARD Slot Quantity : 16" & @CRLF & _ "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " & @CRLF & _ "MPU version information:" & @CRLF & _ "" & @CRLF & _ "MPU (Master) 19 : uptime is 902 days, 1 hour, 16 minutes" & @CRLF & _ " StartupTime 2015/04/16 19:22:14" & @CRLF & _ " SDRAM Memory Size : 2048 M bytes" & @CRLF & _ " FLASH Memory Size : 16 M bytes" & @CRLF & _ " NVRAM Memory Size : 4096 K bytes" & @CRLF & _ " CFCARD Memory Size : 2048 M bytes" & @CRLF & _ " CX6D00MPUK70 version information:" & @CRLF & _ " PCB Version : CX68MPUK REV B" & @CRLF & _ " EPLD Version : 106" & @CRLF & _ " FPGA Version : 107" & @CRLF & _ " BootROM Version : 03.47" & @CRLF & _ " BootLoad Version : 03.47" & @CRLF & _ "" & @CRLF & _ "MPU (Slave) 20 : uptime is 902 days, 1 hour, 14 minutes" & @CRLF & _ " StartupTime 2015/04/16 19:24:06" & @CRLF & _ " SDRAM Memory Size : 2048 M bytes" & @CRLF & _ " FLASH Memory Size : 16 M bytes" & @CRLF & _ " NVRAM Memory Size : 4096 K bytes" & @CRLF & _ " CFCARD Memory Size : 2048 M bytes" & @CRLF & _ " CX6D00MPUK70 version information:" & @CRLF & _ " PCB Version : CX68MPUK REV B" & @CRLF & _ " EPLD Version : 106" & @CRLF & _ " FPGA Version : 107" & @CRLF & _ " BootROM Version : 03.47" & @CRLF & _ " BootLoad Version : 03.47" & @CRLF & _ "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " & @CRLF & _ "NPU version information:" & @CRLF & _ "" & @CRLF & _ "NPU 17 : uptime is 902 days, 1 hour, 14 minutes" & @CRLF & _ " StartupTime 2015/04/16 19:24:17" & @CRLF & _ " Host processor :" & @CRLF & _ " SDRAM Memory Size : 2048 M bytes" & @CRLF & _ " Flash Memory Size : 128 M bytes" & @CRLF & _ " LPU CR5DNPU12070 version information:" & @CRLF & _ " PCB Version : CX68NPU120A REV BCisco IOS XR Software, Version 5.1.3[Default]" & @CRLF & _ "" & @CRLF & _ "RP/0/RSP0/CPU0:RMCOCEM0101#sh ver" & @CRLF & _ "Wed Oct 4 12:47:21.939 BRT" & @CRLF & _ "" & @CRLF & _ "Cisco IOS XR Software, Version 5.1.3[Default]" & @CRLF & _ "" & @CRLF & _ "Copyright (c) 2015 by Cisco Systems, Inc." & @CRLF & _ "" & @CRLF & _ "ROM: System Bootstrap, Version 0.75(c) 1994-2012 by Cisco Systems, Inc." & @CRLF & _ "" & @CRLF & _ "RMCOCEM0101 uptime is 39 weeks, 2 hours, 6 minutes" & @CRLF & _ "System image file is "disk0:asr9k-os-mbi-5.1.3.CSCur21570-1.0.0/0x100305/mbiasr9k-rsp3.vm"" & @CRLF & _ "" & @CRLF & _ "cisco ASR9K Series (Intel 686 F6M14S4) processor with 6291456K bytes of memory." & @CRLF & _ "Intel 686 F6M14S4 processor at 2127MHz, Revision 2.174" & @CRLF & _ "ASR 9006 DC Chassis with PEM Version 2" & @CRLF & _ "" & @CRLF & _ "4 Management Ethernet" & @CRLF & _ "40 GigabitEthernet" & @CRLF & _ "8 TenGigE" & @CRLF & _ "8 DWDM controller(s)" & @CRLF & _ "8 WANPHY controller(s)" & @CRLF & _ "503k bytes of non-volatile configuration memory." & @CRLF & _ "6220M bytes of hard disk." & @CRLF & _ "12510192k bytes of disk0: (Sector size 512 bytes)." & @CRLF & _ "12510192k bytes of disk1: (Sector size 512 bytes)." & @CRLF & _ "" & @CRLF & _ "Configuration register on node 0/RSP0/CPU0 is 0x2102" & @CRLF & _ "Boot device on node 0/RSP0/CPU0 is disk0:" & @CRLF & _ "Package active on node 0/RSP0/CPU0:" & @CRLF & _ "iosxr-fwding-5.1.3.CSCur07854, V 1.0.0[SMU], Cisco Systems, at disk0:iosxr-fwding-5.1.3.CSCur07854-1.0.0" & @CRLF & _ " Built on Fri Oct 17 03:14:03 BRT 2014" & @CRLF & _ " By iox-bld1 in /scratch1/smu/EFR/smu_r51x_5_1_3/workspace for pie" & @CRLF & _ "" & @CRLF & _ "RP/0/RSP0/CPU0:RTARRCE0202#sh ver" & @CRLF & _ "Wed Oct 4 13:06:41.766 BRT" & @CRLF & _ "" & @CRLF & _ "Cisco IOS XR Software, Version 5.1.3[Default]" & @CRLF & _ "Copyright (c) 2015 by Cisco Systems, Inc." & @CRLF & _ "" & @CRLF & _ "ROM: System Bootstrap, Version 0.71(c) 1994-2012 by Cisco Systems, Inc." & @CRLF & _ "" & @CRLF & _ "RTARRCE0202 uptime is 1 year, 28 weeks, 8 hours, 58 minutes" & @CRLF & _ "System image file is "disk0:asr9k-os-mbi-5.1.3.CSCuv70838-1.0.0/0x100305/mbiasr9k-rsp3.vm"" & @CRLF & _ "" & @CRLF & _ "cisco ASR9K Series (Intel 686 F6M14S4) processor with 6291456K bytes of memory." & @CRLF & _ "Intel 686 F6M14S4 processor at 2128MHz, Revision 2.174" & @CRLF & _ "ASR 9006 DC Chassis with PEM Version 2" & @CRLF & _ "" & @CRLF & _ "2 Management Ethernet" & @CRLF & _ "20 TenGigE" & @CRLF & _ "20 DWDM controller(s)" & @CRLF & _ "20 WANPHY controller(s)" & @CRLF & _ "20 GigabitEthernet" & @CRLF & _ "503k bytes of non-volatile configuration memory." & @CRLF & _ "6271M bytes of hard disk." & @CRLF & _ "11817968k bytes of disk0: (Sector size 512 bytes)." & @CRLF & _ "11817968k bytes of disk1: (Sector size 512 bytes)." & @CRLF & _ "" & @CRLF & _ "Configuration register on node 0/RSP0/CPU0 is 0x2102" & @CRLF & _ "Boot device on node 0/RSP0/CPU0 is disk0:" & @CRLF & _ "Package active on node 0/RSP0/CPU0:" & @CRLF & _ "iosxr-fwding-5.1.3.CSCux30811, V 1.0.0[SMU], Cisco Systems, at disk0:iosxr-fwding-5.1.3.CSCux30811-1.0.0" & @CRLF & _ " Built on Fri Dec 11 19:52:18 BRTSUMMERTIME 2015" & @CRLF & _ " By iox-lnx-008 in /san1/smu/EFR/smu_r51x_5_1_3/workspace for pie" & @CRLF & _ "" & @CRLF & _ "asr9k-px-5.1.3.CSCux30811, V 1.0.0[SMU], Cisco Systems, at disk0:asr9k-px-5.1.3.CSCux30811-1.0.0" & @CRLF & _ " Built on Fri Dec 11 19:52:21 BRTSUMMERTIME 2015" & @CRLF & _ " By iox-lnx-008 in /san1/smu/EFR/smu_r51x_5_1_3/workspace for pie" & @CRLF & _ "" & @CRLF & _ "BFGME10#sh ver" & @CRLF & _ "Cisco IOS Software, c7600rsp72043_rp Software (c7600rsp72043_rp-ADVENTERPRISEK9-M), Version 15.3(3)S4, RELEASE SOFTWARE (fc1)" & @CRLF & _ "Technical Support: http://www.cisco.com/techsupport" & @CRLF & _ "Copyright (c) 1986-2014 by Cisco Systems, Inc." & @CRLF & _ "Compiled Fri 19-Sep-14 01:29 by prod_rel_team" & @CRLF & _ "" & @CRLF & _ "ROM: System Bootstrap, Version 12.2(33r)SRE2, RELEASE SOFTWARE (fc1)" & @CRLF & _ "BOOTLDR: Cisco IOS Software, c7600rsp72043_rp Software (c7600rsp72043_rp-ADVENTERPRISEK9-M), Version 15.3(3)S4, RELEASE SOFTWARE (fc1)" & @CRLF & _ "" & @CRLF & _ "BFGME10 uptime is 2 years, 14 weeks, 14 hours, 24 minutes" & @CRLF & _ "Uptime for this control processor is 2 years, 14 weeks, 12 hours, 59 minutes" & @CRLF & _ "System returned to ROM by power cycle (SP by power on)" & @CRLF & _ "System restarted at 23:57:22 UTC Sun Jun 28 2015" & @CRLF & _ "System image file is "sup-bootdisk:/c7600rsp72043-adventerprisek9-mz.153-3.S4.bin"" & @CRLF & _ "Last reload type: Normal Reload" & @CRLF & _ "Last reload reason: power-on" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "This product contains cryptographic features and is subject to United" & @CRLF & _ "States and local country laws governing import, export, transfer and" & @CRLF & _ "use. Delivery of Cisco cryptographic products does not imply" & @CRLF & _ "third-party authority to import, export, distribute or use encryption." & @CRLF & _ "Importers, exporters, distributors and users are responsible for" & @CRLF & _ "compliance with U.S. and local country laws. By using this product you" & @CRLF & _ "agree to comply with applicable laws and regulations. If you are unable" & @CRLF & _ "to comply with U.S. and local laws, return this product immediately." & @CRLF & _ "" & @CRLF & _ "A summary of U.S. laws governing Cisco cryptographic products may be found at:" & @CRLF & _ "http://www.cisco.com/wwl/export/crypto/tool/stqrg.html" & @CRLF & _ "" & @CRLF & _ "<RMAGLRA-LMPN02-01>dis" & @CRLF & _ "<RMAGLRA-LMPN02-01>display ver" & @CRLF & _ "Huawei Versatile Routing Platform Software" & @CRLF & _ "VRP (R) software, Version 8.10 (CX600 V800R007C10)" & @CRLF & _ "Copyright (C) 2012-2014 Huawei Technologies Co., Ltd." & @CRLF & _ "HUAWEI CX600-X2-M8 uptime is 434 days, 2 hours, 3 minutes " & @CRLF & _ "" & @CRLF & _ "CX600-X2-M8 version information:" & @CRLF & _ "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" & @CRLF & _ "BKP version information:" & @CRLF & _ " PCB Version : CX68BKP02B REV B" & @CRLF & _ " MPU Slot Quantity : 2" & @CRLF & _ " NPU Slot Quantity : 2" & @CRLF & _ " CARD Slot Quantity : 8" & @CRLF & _ "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " & @CRLF & _ "MPU version information:" & @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