Regular Expressions 101

Save & Share

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

Substitution

Processing...

Code Generator

Generated Code

re = /^\[((?!(?:ti|ar|al|au|lr|length|by|offset|re|tool|ve|#|\d{1,2}):.+\]).*)\](\r?\n)(\[\d{1,2}:\d{1,2}\.\d{2,3}\])(.*)$/m str = '[ti:Hey You] [ar:Pink Floyd] [al:The Wall (2011 Remaster)] [au:Roger Waters] [lr:Roger Waters] [length:04:40] [by: Casual Tea] [offset:+300] [re: Musicbee] [tool: Mp3tag] [ve: 1.2.3] [#: A comment] [Acoustic Guitar Intro] [Verse 1: David Gilmour] [00:35.485]Hey you [00:38.184]Out there in the cold, [00:39.828]Getting lonely, getting old, [00:41.848]Can you feel me? [00:46.137]Hey you [00:48.659]Standing in the aisles [00:50.250]With itchy feet and fading smiles, [00:52.611]Can you feel me? [00:57.924]Hey, you, don\'t help them to bury the light [01:08.393]Don\'t give in without a fight [01:13.227] [Verse 2: David Gilmour] [01:20.282]Hey, you [01:23.035]Out there on your own, [01:24.566]Sitting naked by the phone, [01:26.685]Would you touch me? [01:30.958]Hey, you [01:33.071]With your ear against the wall, [01:35.171]Waiting for someone to call out, [01:37.348]Would you touch me? [01:42.711]Hey you, would you help me to carry the stone? [01:52.884]Open your heart, I\'m coming home [01:58.076] [Guitar Solo] [Bridge: Roger Waters] [02:57.282]But it was only fantasy [03:04.137]The wall was too high, as you can see [03:11.617]No matter how he tried, he could not break free [03:19.019]And the worms ate into his brain [03:22.914] [Verse 3: Roger Waters] [03:54.974]Hey, you [03:57.745]Out there on the road, [03:59.261]Always doing what you\'re told, [04:01.459]Can you help me? [04:05.745]Hey, you [04:08.135]Out there beyond the wall, [04:09.899]Breaking bottles in the hall, [04:12.108]Can you help me? [04:17.481]Hey, you, don\'t tell me there\'s no hope at all [04:27.360]Together we stand, divided we fall [Outro: Roger Waters] [04:32.742](We fall) [04:34.133](We fall) [04:35.313](We fall) [04:36.593](We fall) [04:37.885](We fall) [04:39.178](We fall) [04:40.433]' subst = '$3($1)$2$3$4' result = str.gsub(re, subst) # Print the result of the substitution puts result

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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html