Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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

$re = '/:\s+\d+\.\d+:\s+\[(?<matching_string>\w+\s+\w+)/m'; $str = '2019-01-17T15:59:28.172+0100: 3093.554: [GC pause (G1 Evacuation Pause) (young), 0.1252055 secs] [Parallel Time: 69.7 ms, GC Workers: 11] [GC Worker Start (ms): Min: 3093555.2, Avg: 3093558.8, Max: 3093566.0, Diff: 10.8] [Ext Root Scanning (ms): Min: 0.0, Avg: 1.6, Max: 8.4, Diff: 8.4, Sum: 17.4] [Update RS (ms): Min: 0.0, Avg: 1.1, Max: 2.3, Diff: 2.3, Sum: 12.0] [Processed Buffers: Min: 0, Avg: 7.5, Max: 33, Diff: 33, Sum: 83] [Scan RS (ms): Min: 0.2, Avg: 1.7, Max: 2.8, Diff: 2.6, Sum: 18.9] [Code Root Scanning (ms): Min: 0.0, Avg: 0.9, Max: 9.0, Diff: 9.0, Sum: 9.8] [Object Copy (ms): Min: 53.7, Avg: 60.6, Max: 63.1, Diff: 9.4, Sum: 666.4] [Termination (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0] [Termination Attempts: Min: 1, Avg: 1.0, Max: 1, Diff: 0, Sum: 11] [GC Worker Other (ms): Min: 0.0, Avg: 0.1, Max: 0.1, Diff: 0.1, Sum: 0.9] [GC Worker Total (ms): Min: 58.8, Avg: 65.9, Max: 69.6, Diff: 10.8, Sum: 725.4] [GC Worker End (ms): Min: 3093624.7, Avg: 3093624.7, Max: 3093624.8, Diff: 0.1] [Code Root Fixup: 0.2 ms] [Code Root Purge: 0.1 ms] [Clear CT: 1.3 ms] [Other: 54.0 ms] [Choose CSet: 0.0 ms] [Ref Proc: 44.6 ms] [Ref Enq: 1.0 ms] [Redirty Cards: 0.4 ms] [Humongous Register: 1.1 ms] [Humongous Reclaim: 0.0 ms] [Free CSet: 6.1 ms] [Eden: 16.5G(16.5G)->0.0B(16.4G) Survivors: 272.0M->456.0M Heap: 18.2G(28.0G)->1871.9M(28.0G)] [Times: user=1.22 sys=0.03, real=0.12 secs] 2019-01-17T16:00:39.144+0100: 3164.525: [Full GC (Heap Inspection Initiated GC) 5595M->1101M(28G), 4.2044268 secs] [Eden: 3720.0M(16.4G)->0.0B(16.8G) Survivors: 456.0M->0.0B Heap: 5595.9M(28.0G)->1101.3M(28.0G)], [Metaspace: 187278K->187274K(1216512K)] [Times: user=5.76 sys=0.06, real=4.20 secs] '; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

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