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 = "(?<=\\<p\\>).+(?=\\<\\/p\\>)"; final String string = "<p>COVEMA</p>\n" + "<p>PALMERO</p>\n" + "<p>PLASTIFERRO</p>\n" + "<p>UOCRA</p>\n" + "<p>REPAS</p>\n" + "<p>BTU</p>\n" + "<p>PANEDILE</p>\n" + "<p>ELEPRINT</p>\n" + "<p>JOSÉ J. CHEDIACK</p>\n" + "<p>NIRO CONSTRUCCIONES</p>\n" + "<p>HELPORT</p>\n" + "<p>BISCAYNE</p>\n" + "<p>COARCO</p>\n" + "<p>ESUCO</p>\n" + "<p>CPC</p>\n" + "<p>TEL 3</p>\n" + "<p>CARTELLONE</p>\n" + "<p>MACRO</p>\n" + "<p>VIAL AGRO</p>\n" + "<p>ISOLUX CORSÁN</p>\n" + "<p>AFCP</p>\n" + "<p>FINNING</p>\n" + "<p>ROGGIO</p>\n" + "<p>ROVELLA CARRANZA</p>\n" + "<p>ACINDAR</p>\n" + "<p>IERIC</p>\n" + "<p>IGARRETA MÁQUINAS</p>\n" + "<p>RIVA</p>\n" + "<p>GRUPO ESTISOL</p>\n" + "<p>IECSA</p>\n" + "<p>ARMAFERRO</p>\n" + "<p>BRICONS</p>\n" + "<p>CNH INDUSTRIAL</p>\n" + "<p>PAOLINI</p>\n" + "<p>SERVIUR</p>\n" + "<p>SANDVIK</p>\n" + "<p>DECAVIAL</p>\n" + "<p>ODEBRECHT</p>\n" + "<p>ENAS</p>\n" + "<p>SITRA</p>\n" + "<p>SUPERCEMENTO</p>\n" + "<p>JCR</p>\n" + "<p>CONSTRUMEX</p>\n" + "<p>BRIALES</p>\n" + "<p>CAPUTO</p>\n" + "<p>LUCIANO</p>\n" + "<p>GALICIA</p>\n" + "<p>VICTOR CONTRERAS</p>\n" + "<p>SIKA ARGENTINA</p>\n" + "<p>CRIBA</p>\n" + "<p>BOETTO Y BUTTIGLIENGO</p>\n" + "<p>MILICIC</p>\n" + "<p>PERIODICO EL CONSTRUCTOR</p>\n" + "<p>PHONERENTAL</p>\n" + "<p>DOS ARROYOS</p>\n" + "<p>MARTINEZ Y DE LA FUENTE</p>\n" + "<p>AUSA</p>\n" + "<p>LUIS LOSI</p>\n" + "<p>AESA</p>\n" + "<p>CONSTRUCTORA SUDAMERICANA</p>\n" + "<p>PLANTEL</p>\n" + "<p>PCR</p>\n" + "<p>BANCO DE LA NACIÓN ARGENTINA</p>\n" + "<p>SUBTERRÁNEOS DE BUENOS AIRES</p>\n" + "<p>HOLA SIM</p>\n" + "<p>JOSÉ LUIS TRIVIÑO</p>\n" + "<p>TECHINT</p>\n" + "<p>EDUARDO COLOMBI</p>\n" + "<p>ALEMARSA</p>\n" + "<p>CENTRO CONSTRUCCIONES</p>\n" + "<p>TECNIPISOS</p>\n" + "<p>XAPOR</p>\n" + "<p>FONTANA NICASTRO</p>\n" + "<p>CONCRET-NOR</p>\n" + "<p>DYCASA</p>\n" + "<p>BURGWARDT</p>\n" + "<p>SULLAIR</p>\n" + "<p>FONDO FIDUCIARIO FEDERAL DE INFRAESTRUCTURA REGIONAL</p>\n" + "<p>FLOWTEX</p>\n" + "<p>PETERSEN THIELE Y CRUZ</p>\n" + "<p>LIHUÉ</p>\n" + "<p>IRAM</p>\n" + "<p>ESTUDIO YMAZ</p>\n" + "<p>VIDOGAR</p>\n" + "<p>BICE</p>\n" + "<p>ROMERO CAMMISA</p>\n" + "<p>BATIMAT</p>\n" + "<p>ALBA CAUCIÓN</p>\n" + "<p>PROBA</p>\n" + "<p>ICF</p>\n" + "<p>TECMA</p>\n" + "<p>ALESTE</p>\n" + "<p>DELEGACIÓN PROVINCIA DE BUENOS AIRES</p>\n" + "<p>HIDRAVIAL</p>\n" + "<p>BANCO CIUDAD</p>\n" + "<p>LAMANNA</p>"; 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