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

/
/

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"^(?P<timestamp>[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}-[0-9]{2}:[0-9]{2})\s+(?P<domain>[a-zA-Z0-9]+)\s+\[(?P<msgid>0[xX][0-9a-fA-F]+)\]\[(?P<msgtype>[a-zA-Z]+)\]\[(?P<msgcat>[a-zA-Z]+)\]\s+(?P<objtype>\w+)\((?P<objname>[a-zA-Z_-]+)\):\s+trans\((?P<txnum>[0-9]+)\)(.*?):\s(?P<msgtxt>.*)"; string input = @"2016-03-16T10:30:18-05:00 DEVESB2 [0x80e0018d][ldap][error] xmlmgr(map-manager): trans(1750947) gtid(1750947): Error querying server 10.158.131.139: Error while searching; see log for details 2016-03-16T10:30:17-05:00 DEVESB2 [0x804000a1][slm][info] throttle(Throttler): trans(1279): Memory(10529899/13448300kB 78.299108 free) Pool(7052687) Ports(127732/127850) Temporary-FS(116/128MB 90.625000 free) File(OK) 2016-03-16T10:30:01-05:00 DEVESB2 [DEVESB][0x80e00176][ws-proxy][error] source-http(DEFAULT_DATA1_HTTP): trans(1750611)[172.27.137.222]: No WS-Proxy service endpoints matched request. "; Match m = Regex.Match(input, pattern); 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