Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
Sponsors
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
Processing...

Test String

Code Generator

Generated Code

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

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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html