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

/
/
gm

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"address\s*\d+\s*range\s(?<srcIp1>\S+)\s*(?<srcIp2>\S+)"; string input = @"[USG6300E]display current-configuration # ip service-set TCP-TSGZ type object 514 service 0 protocol tcp source-port 8801 to 8804 destination-port 0 to 65535 service 1 protocol tcp source-port 12404 destination-port 0 to 65535 # ip service-set GWDK type object 515 service 0 protocol tcp source-port 0 to 65535 destination-port 135 service 1 protocol tcp source-port 0 to 65535 destination-port 137 to 139 service 2 protocol tcp source-port 0 to 65535 destination-port 445 service 3 protocol tcp source-port 0 to 65535 destination-port 3389 service 4 protocol udp source-port 0 to 65535 destination-port 135 service 5 protocol udp source-port 0 to 65535 destination-port 137 to 139 service 6 protocol udp source-port 0 to 65535 destination-port 445 service 7 protocol udp source-port 0 to 65535 destination-port 3389 # ip service-set FXTCP2403 type object 516 service 0 protocol tcp source-port 0 to 65535 destination-port 2403 # ip service-set FXTCP2404 type object 517 service 0 protocol tcp source-port 0 to 65535 destination-port 2404 # ip service-set FXTCPTSGZ type object 518 service 0 protocol tcp source-port 0 to 65535 destination-port 8801 to 8804 service 1 protocol tcp source-port 0 to 65535 destination-port 12404 # ip service-set TCP5149 type object 519 service 0 protocol tcp source-port 0 to 65535 destination-port 5149 to 5150 # ip service-set FXTCP5149 type object 520 service 0 protocol tcp source-port 5149 to 5150 destination-port 0 to 65535 # ip service-set syslo type object 521 service 0 protocol udp source-port 0 to 65535 destination-port 162 service 1 protocol udp source-port 0 to 65535 destination-port 514 # ip service-set UDPCJ type object 522 service 0 protocol udp source-port 0 to 65535 destination-port 161 # ip service-set TCP102 type object 523 service 0 protocol tcp source-port 0 to 65535 destination-port 102 service 1 protocol tcp source-port 102 destination-port 0 to 65535 # ip service-set serviceg1 type group 0 service 0 service-set ntp # ip service-set serviceg2 type group 1 service 0 service-set serviceg1 service 1 service-set FXTCPTSGZ # # ip address-set TSGZZhu type object address 0 range 10.78.48.112 10.78.48.118 # ip address-set TSGZzi type object address 0 10.82.186.11 mask 32 # ip address-set JLzhu type object address 0 range 10.78.44.1 10.78.44.15 # ip address-set JLzi type object address 0 range 10.82.186.5 10.82.186.6 # ip address-set BXzhu type object address 0 range 10.78.48.197 10.78.48.200 # ip address-set BXzi type object address 0 range 10.82.186.9 10.82.186.10 # ip address-set DICPzhu type object address 0 range 10.78.48.39 10.78.48.40 # ip address-set DICPzi type object address 0 10.82.186.4 mask 32 # ip address-set erqu type object address 0 10.85.186.0 mask 27 # ip address-set addressg1 type group address 0 address-set erqu # ip address-set addressg2 type group address 0 address-set addressg1 address 1 address-set DICPzi # "; RegexOptions options = RegexOptions.Multiline; foreach (Match m in Regex.Matches(input, pattern, options)) { Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index); } } }

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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx