Regular Expressions 101

Save & Share

  • Regex Version: ver. 2
  • 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

const regex = /Count\.AutoSlam\.OAK4\.(?P<autoslam>\d+) \[Weekly Avg: (?P<weekly_avrg>\d\.\d{2})\]/gm; // Alternative syntax using RegExp constructor // const regex = new RegExp('Count\\.AutoSlam\\.OAK4\\.(?P<autoslam>\\d+) \\[Weekly Avg: (?P<weekly_avrg>\\d\\.\\d{2})\\]', 'gm') const str = `Label,Min,Avg,Max,Nov 23,11:00,Nov 23,12:00,Nov 23,13:00,Nov 23,14:00,Nov 23,15:00,Nov 23,16:00,Nov 23,17:00,Nov 23,18:00,Nov 23,19:00,Nov 23,20:00,Nov 23,21:00,Nov 23,22:00,Nov 23,23:00,Nov 24,00:00,Nov 24,01:00,Nov 24,02:00,Nov 24,03:00,Nov 24,04:00,Nov 24,05:00,Nov 24,06:00,Nov 24,07:00,Nov 24,08:00,Nov 24,09:00,Nov 24,10:00,Nov 24,11:00,Nov 24,12:00,Nov 24,13:00,Nov 24,14:00,Nov 24,15:00,Nov 24,16:00,Nov 24,17:00,Nov 24,18:00,Nov 24,19:00,Nov 24,20:00,Nov 24,21:00,Nov 24,22:00,Nov 24,23:00,Nov 25,00:00,Nov 25,01:00,Nov 25,02:00,Nov 25,03:00,Nov 25,04:00,Nov 25,05:00,Nov 25,06:00,Nov 25,07:00,Nov 25,08:00,Nov 25,09:00,2 - Count.AutoSlam.OAK4.3. [Weekly Avg: 0.56] 0.0 0.56 2.38 0.0 2.27 0.0 0.0 0.16 0.30 0.25 1.07 1.79 2.38 0.0 0.98 0.0 0.0 0.0 0.0 0.41 0.47 0.60,7 - Count.AutoSlam.OAK4.18 [Weekly Avg: 0.29] 0.0 0.29 2.34 0.0 0.0 0.0 0.0 0.0 0.0 2.34 0.0,5 - Count.AutoSlam.OAK4.13 [Weekly Avg: 0.34] 0.0 0.34 2.08 0.83 0.30 0.32 0.19 0.26 0.47 0.36 0.0 0.22 0.11 0.36 0.65 0.41 0.52 0.85 0.88 1.28 0.0 0.0 1.19 0.0 0.0 0.0 0.0 0.0 2.08 0.0 0.0 0.45 0.79 0.32 0.0 0.0 0.0 0.0 0.0 0.35 0.0 0.15,1 - Count.AutoSlam.OAK4.6. [Weekly Avg: 0.59] 0.0 0.59 1.79 0.0 0.34 0.11 0.38 0.24 0.19 0.15 0.42 0.69 0.56 0.26 1.26 0.71 1.79 1.51 0.82 1.10 1.40 0.57 0.0 0.85 0.34 0.0 0.15 0.29 0.86 0.35 0.39 0.78 1.09 1.35 0.68 0.70 1.02 1.66 1.15 0.31 0.0 0.0 0.0 0.077 0.13,11 - Count.AutoSlam.OAK4.19 [Weekly Avg: 0.23]`; // Reset `lastIndex` if this regex is defined globally // regex.lastIndex = 0; let m; while ((m = regex.exec(str)) !== null) { // This is necessary to avoid infinite loops with zero-width matches if (m.index === regex.lastIndex) { regex.lastIndex++; } // The result can be accessed through the `m`-variable. m.forEach((match, groupIndex) => { console.log(`Found match, group ${groupIndex}: ${match}`); }); }

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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions