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

Substitution

Processing...

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"^.*_(.*)\/.*?(\d\d?)-(\d\d?)-(\d\d?)-(\d).*total images\/sec: (\d*).(\d*)$"; string substitution = @"\1\t\2\t\3\t\4\t\5\t\6,\7"; string input = @"tf_colocation_sync_alexnet/1-1-1-1//logs_han0001i_worker:total images/sec: 126.29 tf_colocation_sync_alexnet/2-2-2-1//logs_han0031i_worker:total images/sec: 284.09 tf_colocation_sync_alexnet/3-3-3-1//logs_han0028i_worker:total images/sec: 380.20 tf_colocation_sync_alexnet/4-4-4-1//logs_han0028i_worker:total images/sec: 433.71 tf_colocation_sync_alexnet/5-5-5-1//logs_han0031i_worker:total images/sec: 563.62 tf_colocation_sync_alexnet/6-6-6-1//logs_han0028i_worker:total images/sec: 650.25 tf_colocation_sync_alexnet/7-7-7-1//logs_han0028i_worker:total images/sec: 714.17 tf_colocation_sync_alexnet/8-8-8-1//logs_han0021i_worker:total images/sec: 771.35 tf_colocation_sync_googlenet/1-1-1-1//logs_han0001i_worker:total images/sec: 103.20 tf_colocation_sync_googlenet/2-2-2-1//logs_han0036i_worker:total images/sec: 195.63 tf_colocation_sync_googlenet/3-3-3-1//logs_han0031i_worker:total images/sec: 296.70 tf_colocation_sync_googlenet/4-4-4-1//logs_han0040i_worker:total images/sec: 397.95 tf_colocation_sync_googlenet/5-5-5-1//logs_han0006i_worker:total images/sec: 501.80 tf_colocation_sync_googlenet/6-6-6-1//logs_han0033i_worker:total images/sec: 601.88 tf_colocation_sync_googlenet/7-7-7-1//logs_han0031i_worker:total images/sec: 694.32 tf_colocation_sync_googlenet/8-8-8-1//logs_han0013i_worker:total images/sec: 793.94 tf_colocation_sync_inception3/1-1-1-1//logs_han0001i_worker:total images/sec: 27.95 tf_colocation_sync_inception3/2-2-2-1//logs_han0032i_worker:total images/sec: 57.89 tf_colocation_sync_inception3/3-3-3-1//logs_han0035i_worker:total images/sec: 86.88 tf_colocation_sync_inception3/4-4-4-1//logs_han0036i_worker:total images/sec: 115.63 tf_colocation_sync_inception3/5-5-5-1//logs_han0040i_worker:total images/sec: 145.01 tf_colocation_sync_inception3/6-6-6-1//logs_han0008i_worker:total images/sec: 173.67 tf_colocation_sync_inception3/7-7-7-1//logs_han0031i_worker:total images/sec: 203.46 tf_colocation_sync_inception3/8-8-8-1//logs_han0035i_worker:total images/sec: 230.64 tf_colocation_sync_resnet152/1-1-1-1//logs_han0001i_worker:total images/sec: 14.61 tf_colocation_sync_resnet152/2-2-2-1//logs_han0032i_worker:total images/sec: 28.89 tf_colocation_sync_resnet152/3-3-3-1//logs_han0023i_worker:total images/sec: 44.70 tf_colocation_sync_resnet152/4-4-4-1//logs_han0031i_worker:total images/sec: 58.99 tf_colocation_sync_resnet152/5-5-5-1//logs_han0007i_worker:total images/sec: 73.51 tf_colocation_sync_resnet152/6-6-6-1//logs_han0026i_worker:total images/sec: 85.85 tf_colocation_sync_resnet152/7-7-7-1//logs_han0031i_worker:total images/sec: 102.79 tf_colocation_sync_resnet152/8-8-8-1//logs_han0035i_worker:total images/sec: 117.12 tf_colocation_sync_resnet50/1-1-1-1//logs_han0001i_worker:total images/sec: 44.83 tf_colocation_sync_resnet50/2-2-2-1//logs_han0040i_worker:total images/sec: 90.92 tf_colocation_sync_resnet50/3-3-3-1//logs_han0004i_worker:total images/sec: 138.23 tf_colocation_sync_resnet50/4-4-4-1//logs_han0008i_worker:total images/sec: 185.06 tf_colocation_sync_resnet50/5-5-5-1//logs_han0032i_worker:total images/sec: 233.60 tf_colocation_sync_resnet50/6-6-6-1//logs_han0031i_worker:total images/sec: 276.48 tf_colocation_sync_resnet50/7-7-7-1//logs_han0008i_worker:total images/sec: 323.27 tf_colocation_sync_resnet50/8-8-8-1//logs_han0035i_worker:total images/sec: 367.67 tf_colocation_sync_vgg16/1-1-1-1//logs_han0001i_worker:total images/sec: 7.85 tf_colocation_sync_vgg16/2-2-2-1//logs_han0035i_worker:total images/sec: 16.75 tf_colocation_sync_vgg16/3-3-3-1//logs_han0040i_worker:total images/sec: 23.14 tf_colocation_sync_vgg16/4-4-4-1//logs_han0037i_worker:total images/sec: 27.65 tf_colocation_sync_vgg16/5-5-5-1//logs_han0031i_worker:total images/sec: 32.54 tf_colocation_sync_vgg16/6-6-6-1//logs_han0008i_worker:total images/sec: 37.42 tf_colocation_sync_vgg16/7-7-7-1//logs_han0034i_worker:total images/sec: 39.26 tf_colocation_sync_vgg16/8-8-8-1//logs_han0040i_worker:total images/sec: 40.95"; RegexOptions options = RegexOptions.Multiline; Regex regex = new Regex(pattern, options); string result = regex.Replace(input, substitution); } }

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