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

/
/
mg

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 = "^.*(LIGNE|Espace|Maintien|point|Delta|ENTREE).*\\n"; final String string = "LIGNE Calque: \"506\"\n" + " Espace: Espace objet\n" + " Maintien = 371b3\n" + " de point, X=103620.0722 Y=49245.7502 Z= 0.0000\n" + " vers point, X=103620.0705 Y=49187.0630 Z= 0.0000\n" + " Longueur = 58.6872, Angle dans le plan XY = 270\n" + " Delta X = -0.0016, Delta Y = -58.6872, Delta Z = 0.0000\n" + " LIGNE Calque: \"506\"\n" + " Espace: Espace objet\n" + " Maintien = 371ad\n" + " de point, X=103810.0724 Y=49255.0701 Z= 0.0000\n" + " vers point, X=103810.0705 Y=49187.0630 Z= 0.0000\n" + " Longueur = 68.0071, Angle dans le plan XY = 270\n" + " Delta X = -0.0019, Delta Y = -68.0071, Delta Z = 0.0000\n" + " LIGNE Calque: \"506\"\n" + " Espace: Espace objet\n" + " Maintien = 371af\n" + " de point, X=104000.0727 Y=49264.3900 Z= 0.0000\n" + "Appuyez sur ENTREE pour continuer:\n" + " vers point, X=104000.0705 Y=49187.0630 Z= 0.0000\n" + " Longueur = 77.3270, Angle dans le plan XY = 270\n" + " Delta X = -0.0022, Delta Y = -77.3270, Delta Z = 0.0000\n" + " LIGNE Calque: \"506\"\n" + " Espace: Espace objet\n" + " Maintien = 371a3\n" + " de point, X=104190.0722 Y=49246.6876 Z= 0.0000\n" + " vers point, X=104190.0705 Y=49187.0630 Z= 0.0000\n" + " Longueur = 59.6246, Angle dans le plan XY = 270\n" + " Delta X = -0.0017, Delta Y = -59.6246, Delta Z = 0.0000\n" + " LIGNE Calque: \"506\"\n" + " Espace: Espace objet\n" + " Maintien = 3718e\n" + " de point, X=104360.0725 Y=49256.5929 Z= 0.0000\n" + " vers point, X=104360.0705 Y=49187.0630 Z= 0.0000\n" + " Longueur = 69.5299, Angle dans le plan XY = 270\n" + " Delta X = -0.0019, Delta Y = -69.5299, Delta Z = 0.0000\n" + " LIGNE Calque: \"506\"\n" + " Espace: Espace objet\n" + "Appuyez sur ENTREE pour continuer:\n" + " Maintien = 37190\n" + " de point, X=104530.0727 Y=49264.3067 Z= 0.0000\n" + " vers point, X=104530.0705 Y=49187.0630 Z= 0.0000\n" + " Longueur = 77.2437, Angle dans le plan XY = 270\n" + " Delta X = -0.0022, Delta Y = -77.2437, Delta Z = 0.0000\n" + " LIGNE Calque: \"506\"\n" + " Espace: Espace objet\n" + " Maintien = 37192\n" + " de point, X=104700.0730 Y=49274.0157 Z= 0.0000\n" + " vers point, X=104700.0705 Y=49187.0630 Z= 0.0000\n" + " Longueur = 86.9527, Angle dans le plan XY = 270\n" + " Delta X = -0.0024, Delta Y = -86.9527, Delta Z = 0.0000\n" + " LIGNE Calque: \"506\"\n" + " Espace: Espace objet\n" + " Maintien = 37194\n" + " de point, X=104920.0731 Y=49278.0638 Z= 0.0000\n" + " vers point, X=104920.0705 Y=49187.0630 Z= 0.0000\n" + " Longueur = 91.0008, Angle dans le plan XY = 270\n" + " Delta X = -0.0025, Delta Y = -91.0008, Delta Z = 0.0000\n" + "Appuyez sur ENTREE pour continuer:\n" + " LIGNE Calque: \"506\"\n" + " Espace: Espace objet\n" + " Maintien = 37196\n" + " de point, X=105140.0731 Y=49278.0638 Z= 0.0000\n" + " vers point, X=105140.0705 Y=49187.0630 Z= 0.0000\n" + " Longueur = 91.0008, Angle dans le plan XY = 270\n" + " Delta X = -0.0025, Delta Y = -91.0008, Delta Z = 0.0000\n" + " LIGNE Calque: \"506\"\n" + " Espace: Espace objet\n" + " Maintien = 37185\n" + " de point, X=105428.0731 Y=49278.0638 Z= 0.0000\n" + " vers point, X=105428.0705 Y=49187.0630 Z= 0.0000\n" + " Longueur = 91.0008, Angle dans le plan XY = 270\n" + " Delta X = -0.0025, Delta Y = -91.0008, Delta Z = 0.0000\n" + " LIGNE Calque: \"506\"\n" + " Espace: Espace objet\n" + " Maintien = 37187\n" + " de point, X=105728.0731 Y=49278.0638 Z= 0.0000\n" + " vers point, X=105728.0705 Y=49187.0630 Z= 0.0000\n" + " Longueur = 91.0008, Angle dans le plan XY = 270\n" + "Appuyez sur ENTREE pour continuer:\n" + " Delta X = -0.0025, Delta Y = -91.0008, Delta Z = 0.0000\n"; final String subst = ""; 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