Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
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 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
Processing...

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 = "commer.{1,5} autour"; final String string = "[NE PAS PRENDRE EN COMPTE]\n" + "----------------------------------------------------------\n" + "-> R1: environnement (\\w{1,5}\\s)?comme\n" + "environnement commercial : boulangerie, supérette, boucherie, coiffeur\n" + "environnement de commerces de proximités (pharmacie,boucherie, boulangerie)\n" + "environnement commerçant (pharmacie, boulangerie, boucherie)\n" + "environnement commerçant composé de : nicolas, paul, boucherie\n\n" + "--------------------------------\n" + "-> R2: enseignes?\n" + "enseignes telles que boulangerie ange, picard, boucherie dubocage et biocoop\n" + "(enseignes : intersport, v&b, picard, marie blachere, pizza, boucherie)\n\n" + "--------------------------------\n" + "-> R3: (voisinage|entour[ée]e)\n" + "entourée d'une pizzeria, coiffeur, bar/tabac/presse, boucherie\n" + "au voisinage, entre autre : restauration rapide, boucherie, vin et liqueur\n" + "voisinage : casino supermarché , burger king, la boucherie\n\n" + "--------------------------------\n" + "-> R4 :\n" + "commodités tout autour (boulangerie pâtisserie, , coiffeurs)\n" + "proximité de commerces tels que : le cic, franprix, boucherie\n\n" + "--------------------------------\n" + "-> R5 :comm.* (de|à) proximit[ée]\n" + "commerces de proximité déjà installés : pharmacie, bar-tabac, boucherie\n" + "commerces de proximité juste à coté : restaurants,boucherie\n\n" + "--------------------------------\n" + "-> R6 : (secteur|p[oô]le|zone|rue|centre) commer.{1,5}\n" + "proche rue commerçante (boulangerie, boucherie)\n" + "près d'une pole commercial composé de boulangeries, boucheries\n" + "dans une zone commerciale constitué boulangerie, boucherie\n" + "dans secteur commercial, boulangerie, boucherie\n" + "situé à l'arrière d'un centre commercial : garage auto, boucherie\n\n" + "--------------------------------\n" + "-> R7 : activit[eé]s (non autoris[eé]e?s?|interdites|exclue?s?)\n" + "activités non autorisées : - restauration (pas d'extraction) et boucherie\n" + "activités interdites : commerce de bouche, boucherie\n" + "activités exclues : commerce de bouche, boucherie\n\n\n" + "--------------------------------\n" + "-> R8 :\n" + "commerces autour : agence immobilière, boulangerie, boucherie\n" + "très bel emplacement, boucherie charcuterie traiteur\n\n" + "--------------------------------\n" + "-> R9 :[aà] (c[oô]té|proximité|autour)\n" + "boucherie charcuterie traiteur autour\n" + "supermarché g20, boucherie à proximité\n" + "supermarché g20, boucherie, boulangerie à côté\n" + "commerces de proximité juste à coté : restaurants,boucherie\n\n\n" + "on y trouve aussi des commerces de proximité, boulangeries\n" + "disposant de nombreux commerces,\n" + "nombreuses offres de restaurations \n" + "proche toutes commodités :\n" + "tous types d'activité à l'exception de boulangerie, boucherie\n" + "services sont à la disposition des utilisateurs :\n" + "centre ville se prête à toutes activités, boulangerie, boucherie\n" + "rue de boucheries \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