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
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 single character of: a, b, c or d
    [[ab][cd]]
  • 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]
  • Character class intersection
    [\w&&[^\d]]
  • 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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

"
"
gmi

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 = "(?:^|\\s)\\S"; final String string = "usdfiusdgfisdgf\n" + "LovePizza\n" + "12,34,56,78\n" + "12.34.56,78\n" + "Esto es una prueba\n" + "hola\n" + "12345678\n" + "45345345343\n" + "Nananananananananananananananana Batman!\n" + "nada@gmail.com\n" + "lorena.loba@loquesea.gov.co\n" + "hola_3@gmail.com\n" + "adios@gmail.com\n" + "pruebagmail.com\n" + "pepe.trueno \n" + "patricia99.rica@.hotmail.com\n" + "lorena22.regalada\n" + "comercio.enproceso\n" + "daniela regalo\n\n" + "gmail.com\n" + "redluis.luis@gmail.com\n" + "pepe_redluis@gmail.com\n" + "pepe_redluis@gmail.com\n" + "mart-red+luis@gmail.com.ve\n\n" + "{\n" + "\"servicio\":\"eval\",\n" + "\"eval\":{\n" + "\"10441\":\"valor.%substr%( 2, 2 )\",\n" + "\"10442\":\"valor\",\n" + "\"10443\":\"%mask%(valor,3)\"\n" + "},\n" + "\"operacion\":\"valor.%concat%(10442,10443,10441)\",\n" + "\"resultado\":12022\n" + "}\n\n\n" + "1. Luciana: 4.216 \n" + "2. Isabella: 3.505 \n" + "3. Salomé: 2.829\n" + "4. Emmanuel: 2.688\n" + "5. Antonella: 2.643\n" + "6. Emiliano: 2454\n" + "7. Santiago: 2.383\n" + "8. Samuel: 2.256\n" + "9. Jerónimo: 2.167\n" + "10. Mariana: 2.160\n\n" + "date,home_team,away_team,home_score,away_score,tournament,city,country,neutral\n" + "1872-11-30,Scotland,England,0,0,Friendly,Glasgow,Scotland,FALSE\n" + "1873-03-08,England,Scotland,4,2,Friendly,London,England,FALSE\n" + "1874-03-07,Scotland,England,2,1,Friendly,Glasgow,Scotland,FALSE\n" + "1875-03-06,England,Scotland,2,2,Friendly,London,England,FALSE\n" + "1876-03-04,Scotland,England,3,0,Friendly,Glasgow,Scotland,FALSE\n" + "1876-03-25,Scotland,Wales,4,0,Friendly,Glasgow,Scotland,FALSE\n\n" + "1::Toy Story (1995)::Adventure|Animation|Children|Comedy|Fantasy\n" + "2::Jumanji (1995)::Adventure|Children|Fantasy\n" + "3::Grumpier Old Men (1995)::Comedy|Romance\n" + "4::Waiting to Exhale (1995)::Comedy|Drama|Romance\n" + "5::Father of the Bride Part II (1995)::Comedy\n" + "6::Heat (1995)::Action|Crime|Thriller\n" + "7::Sabrina (1995)::Comedy|Romance\n" + "8::Tom and Huck (1995)::Adventure|Children\n" + "9::Sudden Death (1995)::Action\n" + "10::GoldenEye (1995)::Action|Adventure|Thriller\n" + "11::American President, The (1995)::Comedy|Drama|Romance\n" + "12::Dracula: Dead and Loving It (1995)::Comedy|Horror\n" + "13::Balto (1995)::Animation|Children\n" + "14::Nixon (1995)::Drama\n" + "15::Cutthroat Island (1995)::Action|Adventure|Romance\n" + "16::Casino (1995)::Crime|Drama\n" + "17::Sense and Sensibility (1995)::Comedy|Drama|Romance\n" + "18::Four Rooms (1995)::Comedy|Drama|Thriller\n" + "19::Ace Ventura: When Nature Calls (1995)::Comedy\n" + "20::Money Train (1995)::Action|Comedy|Crime|Drama|Thriller"; final String subst = ""; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); 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