Regular Expressions 101

Save & Share

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 = "^.*?\\((.*)\\).*$"; final String string = " claudiu.cismaru (Claudiu Cismaru) SPEAKER\n" + " radu.mihailas (Radu Mihăilă) SPEAKER\n" + " alex_macau (Alex Macau) SPEAKER\n" + " angela.milas (Angela Palcu) SPEAKER\n" + " andrada.rupacici (Andrada Rupacici) SPEAKER\n" + " gary_star (Gabi Gidei) SPEAKER\n" + " mihai.moje (Mihai Moje) ADMIN\n" + " paul.ciocmareanu (Paul Adrian Ciocmareanu) SPEAKER\n" + " ionut.marghidanu (Ionut Marghidanu) SPEAKER\n" + " eduard.hirsch (Eduard Hirsch) SPEAKER\n" + " simonabelintan (Simona Bitu) SPEAKER\n" + " ade.scutca (Adela Scutca) SPEAKER\n" + " roibu-florin (Florin Roibu) SPEAKER\n" + " live:oanamariavlad (Oana Poenar (Vlad)) SPEAKER\n" + " live:andrei.trancota (Andrei Trancota) SPEAKER\n" + " live:ozy24us (Emanuel Craciun) SPEAKER\n" + " adrian.mosneagu23 (Adrian Mosneagu) SPEAKER\n" + " daniela.busu (Daniela Busu) SPEAKER\n" + " live:florin.turdasan (Florin Turdasan) SPEAKER\n" + " live:daniel.boita_1 (Daniel Boita) SPEAKER\n" + " denis.buliga (Denis Buliga) SPEAKER\n" + " live:jean.goujon_1 (Jean-Baptiste Goujon) SPEAKER\n" + " jurjandrei90 (Andrei Jurj) SPEAKER\n" + " i_pasca (Ioan Pasca) SPEAKER\n" + " claudiu0386 (Claudiu Mardarasevici) SPEAKER\n" + " didi.popoviciu (Didi Popoviciu) SPEAKER\n" + " anda.lele (Alexandra Lele) SPEAKER\n" + " lorand.varga (Lorand Varga) SPEAKER\n" + " live:412602f6b1e34602 (Mihaela Lemeni) SPEAKER\n" + " lvudesign (Liviu Iancu) SPEAKER\n" + " octavia_stancu (Ava Stancu) SPEAKER\n" + " live:422c271cb4bb230c (Beatrice Blidariu) SPEAKER\n" + " live:raresistoc1_1 (Rares Istoc) SPEAKER\n" + " live:octavia_octi30 (Octavia Bradea) SPEAKER\n" + " live:paula.dragoman (Paula Dragoman) SPEAKER\n" + " live:sanda.popoiu (Sanda Popoiu) ADMIN\n" + " live:aciu.alexandru (Alexandru Aciu) ADMIN\n" + " live:sirbu.sorin.cristian (Sorin Sirbu) SPEAKER\n" + " live:ana.tutuianu_1 (Ana Tutuianu) SPEAKER\n" + " narcis.oancea (narcis oancea) ADMIN\n" + " live:raresturc (Turc Rares) ADMIN\n" + " live:8922ae5e5ee0572e (Eduard Daniel Cocirla) SPEAKER\n" + " adelabalans (Adela Balan) ADMIN\n" + " tudor.vioreanu (Tudor Vioreanu) ADMIN\n" + " live:madalin.crestescu (Madalin Crestescu) SPEAKER\n" + " live:bokorb (Bokor Béla) SPEAKER\n" + " live:lavinia.a.stoia (Lavinia Stoia) ADMIN\n" + " timoce.ana (Ana Tutuianu) SPEAKER\n" + " live:ded6104985160d9b (Mircea Grigoras) SPEAKER\n" + " iancic.bogdan (Bogdan Iancic) SPEAKER"; final String subst = "$1"; 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