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

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "^\\[((?!(?: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}\\])(.*)$"; final String string = "[ti:Hey You]\n" + "[ar:Pink Floyd]\n" + "[al:The Wall (2011 Remaster)]\n" + "[au:Roger Waters]\n" + "[lr:Roger Waters]\n" + "[length:04:40]\n" + "[by: Casual Tea]\n" + "[offset:+300]\n" + "[re: Musicbee]\n" + "[tool: Mp3tag]\n" + "[ve: 1.2.3]\n" + "[#: A comment]\n\n" + "[Acoustic Guitar Intro]\n\n" + "[Verse 1: David Gilmour]\n" + "[00:35.485]Hey you\n" + "[00:38.184]Out there in the cold,\n" + "[00:39.828]Getting lonely, getting old,\n" + "[00:41.848]Can you feel me?\n" + "[00:46.137]Hey you\n" + "[00:48.659]Standing in the aisles\n" + "[00:50.250]With itchy feet and fading smiles,\n" + "[00:52.611]Can you feel me?\n" + "[00:57.924]Hey, you, don't help them to bury the light\n" + "[01:08.393]Don't give in without a fight\n" + "[01:13.227]\n" + "[Verse 2: David Gilmour]\n" + "[01:20.282]Hey, you\n" + "[01:23.035]Out there on your own,\n" + "[01:24.566]Sitting naked by the phone,\n" + "[01:26.685]Would you touch me?\n" + "[01:30.958]Hey, you\n" + "[01:33.071]With your ear against the wall,\n" + "[01:35.171]Waiting for someone to call out,\n" + "[01:37.348]Would you touch me?\n" + "[01:42.711]Hey you, would you help me to carry the stone?\n" + "[01:52.884]Open your heart, I'm coming home\n" + "[01:58.076]\n" + "[Guitar Solo]\n\n" + "[Bridge: Roger Waters]\n" + "[02:57.282]But it was only fantasy\n" + "[03:04.137]The wall was too high, as you can see\n" + "[03:11.617]No matter how he tried, he could not break free\n" + "[03:19.019]And the worms ate into his brain\n" + "[03:22.914]\n" + "[Verse 3: Roger Waters]\n" + "[03:54.974]Hey, you\n" + "[03:57.745]Out there on the road,\n" + "[03:59.261]Always doing what you're told,\n" + "[04:01.459]Can you help me?\n" + "[04:05.745]Hey, you\n" + "[04:08.135]Out there beyond the wall,\n" + "[04:09.899]Breaking bottles in the hall,\n" + "[04:12.108]Can you help me?\n" + "[04:17.481]Hey, you, don't tell me there's no hope at all\n" + "[04:27.360]Together we stand, divided we fall\n\n" + "[Outro: Roger Waters]\n" + "[04:32.742](We fall)\n" + "[04:34.133](We fall)\n" + "[04:35.313](We fall)\n" + "[04:36.593](We fall)\n" + "[04:37.885](We fall)\n" + "[04:39.178](We fall)\n" + "[04:40.433]"; final String subst = "$3($1)$2$3$4"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); final Matcher matcher = pattern.matcher(string); // The substituted value will be contained in the result variable final String result = matcher.replaceAll(subst); System.out.println("Substitution result: " + 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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html