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 (14)

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

/
/

Test String

Substitution

Processing...

Code Generator

Generated Code

$re = '/MDS\s*\d+\s+([^\r\n\s]+)[^\r\n]*\s+Chassis/'; $str = '1469481745 1 Host/Cisco/show_ver=Cisco Nexus Operating System (NX-OS) Software\\r\\nTAC support: http://www.cisco.com/tac\\r\\nCopyright (C) 2002-2015, Cisco and/or its affiliates.\\r\\nAll rights reserved.\\r\\nThe copyrights to certain works contained in this software are\\r\\nowned by other third parties and used and distributed under their own\\r\\nlicenses, such as open source. This software is provided "as is," and unless\\r\\notherwise stated, there is no warranty, express or implied, including but not\\r\\nlimited to warranties of merchantability and fitness for a particular purpose.\\r\\nCertain components of this software are licensed under\\r\\nthe GNU General Public License (GPL) version 2.0 or \\r\\nGNU General Public License (GPL) version 3.0 or the GNU\\r\\nLesser General Public License (LGPL) Version 2.1 or \\r\\nLesser General Public License (LGPL) Version 2.0. \\r\\nA copy of each such license is available at\\r\\nhttp://www.opensource.org/licenses/gpl-2.0.php and\\r\\nhttp://opensource.org/licenses/gpl-3.0.html and\\r\\nhttp://www.opensource.org/licenses/lgpl-2.1.php and\\r\\nhttp://www.gnu.org/licenses/old-licenses/library.txt.\\r\\n\\r\\nSoftware\\r\\n BIOS: version 07.34\\r\\n NXOS: version 7.0(3)I2(2a)\\r\\n--More--\\r BIOS compile time: 08/11/2015\\r\\n NXOS image file is: bootflash:///nxos.7.0.3.I2.2a.bin\\r\\n NXOS compile time: 12/14/2015 4:00:00 [12/14/2015 12:23:53]\\r\\n\\r\\n\\r\\nHardware\\r\\n cisco Nexus9000 C9332PQ chassis \\r\\n Intel(R) Core(TM) i3- CPU @ 2.50GHz with 16401956 kB of memory.\\r\\n Processor Board ID SAL183606N7\\r\\n\\r\\n Device name: ITC-GCC01-SP01\\r\\n bootflash: 7906304 kB\\r\\nKernel uptime is 0 day(s), 2 hour(s), 51 minute(s), 10 second(s)\\r\\n\\r\\nLast reset \\r\\n Reason: Unknown\\r\\n System version: 7.0(3)I2(2a)\\r\\n Service: \\r\\n\\r\\nplugin\\r\\n Core Plugin, Ethernet Plugin\\r\\n\\r\\nActive Package(s):\\r\\n--More--\\r nxos.CSCuy36553_TOR-1.0.0-7.0.3.I2.2a.lib32_n9000\\r\\n\\r'; $subst = ""; $result = preg_replace($re, $subst, $str, 1); echo "The result of the substitution is ".$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 PHP, please visit: http://php.net/manual/en/ref.pcre.php