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

use strict; my $str = 'Nel 1996 i governatori della) BERS hanno deciso di raddoppiare il capitale autorizzato della Banca, a) per il quale l\'Unione ha sottoscritto ulteriori 3 000 azioni del i) valore di 1 000 EUR ciascuna. 26.10 26.10.2302 ° Conformément à l’article 14, paragraphe 5 bis, du règlement de base, à moins qu’elle ne dispose d’éléments de preuve suffisants au sens de l’article 5 démontrant que les conditions prévues à l’article 10, paragraphe 4, points c) ou d), ne sont pas remplies, la Commission enregistre les importations faisant l’objet d’une enquête antidumping au cours de la période de notification préalable. 12.88 Les esters (d’alkylphosphate sont définis comme étant certains esters d’alkylphosphate fabriqués exclusivement sur des chaînes (latérales d’une longueur de deux ou trois atomes de carbone (y compris les chaînes alkylées chlorées) et ayant une teneur en phosphore d’au moins 9 % (en poids) et une viscosité comprise entre 1 et 100 mPa.s à 20-25 °), relevant des numéros CAS 13674-84-5, 1244733-77-4 et 78-40-0. Selon une communication de Kingspan, une quantité moindre de TEP est nécessaire pour remplacer le TCPP (environ 1,8 kg de TCPP est nécessaire pour remplacer 1 kg de TEP), ce qui compenserait partiellement le coût de production plus élevé du TEP. La production totale de (l’Union au cours de la période d’enquête s’est établie à environ 18.274 tonnes. (i) Conformément à l’article (l 14, paragraphe 5a, du règlement de base, à moins qu’elle ne dispose d’éléments de preuve suffisants) au sens de l’article 5 démontrant que les conditions prévues à l’article 10, paragraphe 4, points (c) ou (d), 1234 ne sont pas remplies, la Commission enregistre les importations faisant l’objet d’une enquête antidumping au cours de la période de notification préalable). du règlement (UE) 2015/755 du Parlement européen et du Conseil i) allala Lalala) not lalala, (and lalala. Lalala not lalala, (and lalala Ok, (here\'s some context. I need regex that will match the missing opening bracket here: \'Here, since I\'m so good at tpying), I forgot to open the brackets.\' but not here: \'du (Parlement européen) et du Conseil.'; my $regex = qr/(\A|\)|\.)[^\(]*?(?:[a-z]{2,})\)/mp; if ( $str =~ /$regex/g ) { print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n"; # print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n"; # print "Capture Group 2 is $2 ... and so on\n"; } # ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p' # Named capture groups can be called via $+{name}

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 Perl, please visit: http://perldoc.perl.org/perlre.html