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 = /\> .+\s+(?<text>[\w\W]+?)(?=\s+\d+\s+|$)/g; // Alternative syntax using RegExp constructor // const regex = new RegExp('\\> .+\\s+(?<text>[\\w\\W]+?)(?=\\s+\\d+\\s+|$)', 'g') const str = `1 00:00:00,000 --> 00:00:00,500 moi j'ai fait des 2 00:00:00,500 --> 00:00:01,780 rêves lucides 3 00:00:01,780 --> 00:00:03,340 mais j’ai jamais essayé 4 00:00:03,340 --> 00:00:03,820 d'en faire 5 00:00:03,820 --> 00:00:04,700 ou quoi 6 00:00:04,700 --> 00:00:05,500 J'ai dû en faire 7 00:00:05,500 --> 00:00:06,720 genre cinq 8 00:00:06,720 --> 00:00:07,380 mais il y en 9 00:00:07,380 --> 00:00:09,160 a deux des cinq où vraiment 10 00:00:09,160 --> 00:00:10,260 je faisais ce que je veux 11 00:00:10,260 --> 00:00:11,080 Genre j'ai volé 12 00:00:11,080 --> 00:00:12,100 tout ce à quoi je pensais 13 00:00:12,100 --> 00:00:12,720 je le faisais 14 00:00:12,720 --> 00:00:13,260 c'était vraiment 15 00:00:13,260 --> 00:00:14,040 tranquille bon c'était 16 00:00:14,040 --> 00:00:14,640 pendant ma période 17 00:00:14,640 --> 00:00:16,140 où j'étais un peu 18 00:00:16,140 --> 00:00:16,800 dans un autre monde 19 00:00:16,800 --> 00:00:17,360 de manière générale 20 00:00:17,360 --> 00:00:17,720 Et j'ai fait 21 00:00:17,720 --> 00:00:18,820 l'inverse aussi 22 00:00:18,820 --> 00:00:20,460 où j'étais réveillé Ça 23 00:00:20,460 --> 00:00:20,800 j'ai jamais 24 00:00:20,800 --> 00:00:21,280 fait Par contre 25 00:00:21,280 --> 00:00:21,900 et heureusement 26 00:00:21,900 --> 00:00:22,580 parce que ça a l'air 27 00:00:22,580 --> 00:00:23,680 tellement flippant 28 00:00:23,680 --> 00:00:24,740 J'adorais vivre ça 29 00:00:24,740 --> 00:00:26,100 ah t’es unn malade 30 00:00:26,100 --> 00:00:26,740 Mais attendez 31 00:00:26,740 --> 00:00:27,960 une expérience négative 32 00:00:27,960 --> 00:00:28,920 est une bonne expérience 33 00:00:28,920 --> 00:00:30,620 Moi j'ai une amoureuse 34 00:00:30,620 --> 00:00:31,520 qui vit ça 35 00:00:31,520 --> 00:00:32,140 très souvent 36 00:00:32,140 --> 00:00:32,460 j’ai pas envie 37 00:00:32,460 --> 00:00:32,880 d'en faire 20 38 00:00:32,880 --> 00:00:33,740 mais et je peux te dire 39 00:00:33,740 --> 00:00:35,020 qu'elle n'en peut plus quoi`; // 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