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
No Match

/
/
g

Test String

Code Generator

Generated Code

const regex = /var datas ?= ?\{ ?(?: ?"[^"]+" ?: ?\{ ?"titre" ?: ?(?:(?:"(?:[^"]|\\")*[^\\]")|(?:'(?:[^']|\\')*[^\\]')) ?, ?(?:"\d+" ?: ?\d+ ?(?:(?:, ?(?=(?:"\d)|\}))|(?=\}))){1,} ?\} ?(?:(?:, ?(?=["}]))|(?=\}))){2,7}\}/g; // Alternative syntax using RegExp constructor // const regex = new RegExp('var datas ?= ?\\{ ?(?: ?"[^"]+" ?: ?\\{ ?"titre" ?: ?(?:(?:"(?:[^"]|\\\\")*[^\\\\]")|(?:\'(?:[^\']|\\\\\')*[^\\\\]\')) ?, ?(?:"\\d+" ?: ?\\d+ ?(?:(?:, ?(?=(?:"\\d)|\\}))|(?=\\}))){1,} ?\\} ?(?:(?:, ?(?=["}]))|(?=\\}))){2,7}\\}', 'g') const str = `var datas = { "XiaoMei": { "titre" : "Xiao-Mei", "0" : 113, "1" : 39, "2" : 128, "3" : 386, "4" : 481, "5" : 69, "6" : 25, "7" : 142, "8" : 141, "9" : 32, "10" : 533, "11" : 27, "12" : 87, "13" : 125, "14" : 124, "15" : 98, "16" : 531 }, "RossBelles": { "titre" : "Scott Ross, les + belles", "0" : 1, "1" : 9, "2" : 14, "3" : 27, "4" : 38, "5" : 103, "6" : 114, "7" : 141, "8" : 208, "9" : 213, "10" : 296, "11" : 297, "12" : 298, "13" : 299, "14" : 380, "15" : 490, "16" : 491, "17" : 492, "18" : 555 }, "Ross561": { "titre" : "Scott Ross, antho. 1", "0" : 33, "1" : 34, "2" : 60, "3" : 67, "4" : 69, "5" : 87, "6" : 94, "7" : 95, "8" : 96, "9" : 97, "10" : 104, "11" : 107, "12" : 113, "13" : 114, "14" : 132, "15" : 133, "16" : 140, "17" : 141, "18" : 144, "19" : 145 }, "Ross562": { "titre" : "Scott Ross, antho. 2", "0" : 146, "1" : 178, "2" : 187, "3" : 201, "4" : 203, "5" : 204, "6" : 205, "7" : 208, "8" : 209, "9" : 211, "10" : 212, "11" : 213, "12" : 214, "13" : 238, "14" : 239, "15" : 259, "16" : 260 }, "Ross563": { "titre" : "Scott Ross, antho. 3", "0" : 241, "1" : 261, "2" : 262, "3" : 298, "4" : 318, "5" : 319, "6" : 364, "7" : 365, "8" : 366, "9" : 381, "10" : 402, "11" : 403, "12" : 426, "13" : 427, "14" : 429, "15" : 455, "16" : 513, "17" : 544, "18" : 545 }, "Staier": { "titre" : "Staier", "0" : 427, "1" : 426, "2" : 415, "3" : 414, "4" : 209, "5" : 208, "6" : 247, "7" : 246, "8" : 513, "9" : 216, "10" : 215, "11" : 114, "12" : 113, "13" : 69, "14" : 116, "15" : 115, "16" : 395, "17" : 394} } `; // 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