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

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 = "^\"(?'tsy_lib'.*?)\";(?:.*?;){4}\"(?'num_externe'.*?)\";(?:.*?;){3}\"(?'apt_nom'.*?)\";\"(?'apt_telephone'.*?)\";(?:.*?;)\"(?'apt_localisation'.*?)\";(?:.*?;)\"(?'ins_libl'.*?)\";(?:.*?;){5}\"(?'apt_e_mail'.*?)\";(?:.*?;){2}\"(?'commentaire_externe'.+)\""; final String string = "\"D01.00.00\";\"005291\";\"CG45\";\"15085\";\"cnt_ext\";\"1906151751\";181856;\"A05\";\"dem_ext\";\"LARDEAU Benoit\";\"02 36 99 26 02\";\"site_ext\";\"COLLEGE PAUL ELUARD\";\"SIT_036\";\"COLLEGE PAUL ELUARD\";\"TEST_Pose d'un portier video\";\"19/06/2019 00:00\";\"SUEUR Olivier\";\"02 38 85 51 55\";\"\";\"olivier.sueur_¿_ac-orleans-tours.fr\";\"12/07/2019 00:00\";002;0;\"Pose d'un portier vidéo pour le portillon d'accès aux logements de fonction.[Test D01 BLA 20190619]\"\n\n" + "\"D01.00.00\";\"005291\";\"CG45\";\"15085\";\"cnt_ext\";\"1906151755\";181860;\"A05\";\"dem_ext\";\"LARDEAU Benoit\";\"02 36 99 26 02\";\"site_ext\";\"COLLEGE LOUIS PASTEUR\";\"SIT_036\";\"COLLEGE LOUIS PASTEUR\";\"TEST_Remplacement extincteur\";\"19/06/2019 00:00\";\"PETIT Anne\";\"02 38 72 65 81\";\"\";\"anne.petit_¿_ac-orleans-tours.fr\";\"11/07/2019 00:00\";003;0;\"Bonjour, l'extincteur n° 137 839 a été déclaré inutilisable en l'état lors de la dernière vérification, date de validité dépassée. Merci de prévoir le remplacement à l'identique.\"\n\n" + "\"D01.00.00\";\"005291\";\"CG45\";\"15085\";\"cnt_ext\";\"1906151750\";181855;\"A05\";\"dem_ext\";\"LARDEAU Benoit\";\"02 36 99 26 02\";\"site_ext\";\"HOTEL DU DEPARTEMENT\";\"SIT_043\";\"HOTEL DU DEPARTEMENT\";\"TEST_Remplacement prises\";\"19/06/2019 00:00\";\"DESCAMPS Matthieu\";\"02 38 25 43 01\";\"06 45 37 64 85\";\"matthieu.descamps_¿_loiret.fr\";\"26/06/2019 00:00\";003;0;\"Remplacement de quatre blocs de prises au centre de documentation. [Test D01 BLA 20190619]\"\n\n" + "\"D01.00.00\";\"005291\";\"CG45\";\"15085\";\"cnt_ext\";\"1906151753\";181858;\"A05\";\"dem_ext\";\"LARDEAU Benoit\";\"02 36 99 26 02\";\"site_ext\";\"COLLEGE MONTABUZARD\";\"SIT_008\";\"SALLE POLYVALENTE MONTABUZARD\";\"TEST_Pose de serrures local stockage\";\"19/06/2019 00:00\";\"MORVAN Béatrice\";\"02 38 74 71 98\";\"\";\"beatrice.dixon_¿_ac-orleans-tours.fr\";\"27/06/2019 00:00\";002;0;\"Pose de serrures sur les trois portes d'accès au local de stockage. [Test D01 BLA 20190619]\"\n" + "\"D01.00.00\";\"005291\";\"CG45\";\"15085\";\"cnt_ext\";\"1906151752\";181857;\"A05\";\"dem_ext\";\"LARDEAU Benoit\";\"02 36 99 26 02\";\"site_ext\";\"COLLEGE MONTABUZARD\";\"SIT_036\";\"COLLEGE MONTABUZARD\";\"TEST_Remplacement chauffe-eau\";\"19/06/2019 00:00\";\"MORVAN Béatrice\";\"02 38 74 71 98\";\"\";\"beatrice.dixon_¿_ac-orleans-tours.fr\";\"04/07/2019 00:00\";003;0;\"Remplacement du chauffe-eau du vestiaire du personnel [Test D01 BLA 20190619]\"\n" + "\"D01.00.00\";\"005291\";\"CG45\";\"15085\";\"cnt_ext\";\"1906151754\";181859;\"A05\";\"dem_ext\";\"LARDEAU Benoit\";\"02 36 99 26 02\";\"site_ext\";\"COLLEGE CLOS FERBOIS\";\"SIT_036\";\"COLLEGE CLOS FERBOIS\";\"TEST_Pose de 6 blocs de 4 prises\";\"19/06/2019 00:00\";\"ROGER Angéline\";\"02 38 59 72 70\";\"\";\"Angeline.Roger_¿_ac-orleans-tours.fr\";\"30/08/2019 00:00\";004;0;\"Pose de 6 blocs de 4 prises en salle de dessin pour raccordements PC portables.[Test D01 BLA 20190619]\"\n"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

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