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
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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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"
"
gm

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"(?P<time>\d{8}T\d{6}) (?P<rti>.+) (?P<timestamp>\d+)\s?Bus=\s?(?P<bus>.*?)\s?C=\s?0x(?P<cmd>[0-9a-fA-F]{2})\s?S=\s?(?P<status>\w+)\s?RT=\s?(?P<rt>\d+)\s?RDI=\s?0x(?P<rdi>[0-9a-fA-F]{2})\s?EOT=\s?0x(?P<eot>[0-9a-fA-F]{2})\s?Data=\s?(?P<data>([0-9a-fA-F]{2}\s?)*)\s?REPLY=\s?(?P<reply>([0-9a-fA-F]{2}\s?)*)"; string input = @"20141011T042032 - 14362918521340 Bus=PsycheMbusSia2-A C=0xc8 S=RESP RT=08 RDI=0x06 EOT=0x0c Data=84 9f REPLY=4f c0 c0\n 20200515T000132 4 2338257812 Bus=PsycheMbusSia2-A C=0xc8 S=RESP RT=08 RDI=0x1c EOT=0x04 Data= 83 90 88 93 8b 98 88 90 REPLY= 3f 20200515T000132 4 2338257812 Bus=PsycheMbusSia2-A C=0xc8 S=RESP RT=08 RDI=0x1c EOT=0x04 Data=REPLY= 3f 20200515T000140 12 2343757812 Bus=PsycheMbusSia2-A C=0xc8 S=RESP RT=08 RDI=0x03 EOT=0x0C Data= 84 9c REPLY= 4c c0 c0 "; 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