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

/
/
g

Test String

Substitution

Processing...

Code Generator

Generated Code

$re = '/(src|href)\s*=\s*"[^" ]*\K\h|(?!^)\G[^" ]*\K\h/'; $str = 'http://massimodifa.com/dev-area/stefano-busonero/perl-project/wp-11-15/dal Gotico/13-02 Frammenti pittori rococo.htm http://www.frammentiarte.it/dal%20Gotico/Pittori%20lombardi%20opere/32%20Daniele%20Ranzoni%20-%20La%20principessa%20Saint%20L%C3%A9ger.jpg <div> <div class="rTable"> <div class="rTableRow"> <div class="rTableCell"> <p align="center"><span style="font-size: small;"><b>Beato Angelico: Pala di San Marco</b></span> Predella: ottavo scomparto La sepoltura dei santi Cosma e Damiano</p> <div class="rTable"> <div class="rTableRow"> <div class="rTableCell"><img src="http://massimodifa.com/dev area/stefano-busonero/perl-project/wp-11-15/wp-content/uploads/2016/02/dal Gotico/Beato Angelico%20opere/20-beato-angelico-pala-di-san-marco.jpg" alt="La sepoltura dei Santi Cosma e Damiano" width="864" height="676" /></div> </div> </div> <div class="rTable"> <div class="rTableRow"> <div class="rTableCell">Predella: ottavo scomparto La sepoltura dei santi Cosma e Damiano, cm. 37 x 45, Museo di San Marco, Firenze.</div> </div> </div> <div class="rTable"> <div class="rTableRow"> <div class="rTableCell"><a href="http://massimodifa.com/dev-area/stefano-busonero/perl-project/wp-11-15/dal%20Gotico/Beato%20Angelico%20opere/19-decapitazione-s.-cosma-e-s.-damiano"><span style="font-size: small;">Alla "Decapitazione dei santi"</span></a></div> <div class="rTableCell"><a href="http://massimodifa.com/dev-area/stefano-busonero/perl-project/wp-11-15/dal%20Gotico/Beato%20Angelico%20opere/12-pala-di-san-marco"><span style="font-size: small;">Ritorna all\'elenco raffigurazioni Pala di San Marco</span></a></div> <div class="rTableCell"><a href="http://massimodifa.com/dev area/stefano-busonero/perl project/wp-11-15/dal%20Gotico/Beato%20Angelico opere/21-guarigione-del-diacono">Alla "Guarigione del diacono Giustiniano"</a></div> </div> </div> <a href="http://massimodifa.com/dev-area/stefano-busonero/perl-project/wp-11-15/dal%20Gotico/Beato%20Angelico opere/0-beato-angelico-opere"><span style="font-size: small;">Ritorna all\'elenco opere di Beato Angelico</span></a> <p align="justify"><span style="font-size: small;">        </span></p> <div class="rTable"> <div class="rTableRow"> <div class="rTableCell"></div> <div class="rTableCell"> <p class="style10" align="justify">Sull\'opera: "La sepoltura dei santi Cosma e Damiano" è un dipinto di Beato Angelico, appartenente alla predella della "Pala di San Marco", realizzato con tecnica a tempera su tavola nel 1438-40, misura 37 x 45 cm. ed è custodito nel Museo di San Marco a Firenze.</p> <p class="style10" align="justify"></p> <p class="style10" align="justify">Prima di pervenire al Museo di San Marco l\'opera si trovava all\'Accademia di Belle Arti di Firenze. La storia narrata in questa composizione è certamente tratta da un episodio della Legenda aurea, dove il dromedario che trasportava le spoglie di san Damiano incominciò improvvisamente a parlare ordinando di seppellire il santo vicino ai fratelli, di cui si stavano contemporaneamente celebrando le esequie. La scena è ambientata in piazza San Marco, con il convento non ancora completamente edificato (mancante del piano superiore, adiacente alla facciata della chiesa. Sia l\'appartenenza alla predella della pala in esame, che l\'autografia dell\'Angelico, sono accettate universalmente con favore dalla critica ufficiale.</p> </div> </div> </div> <div class="rTable"> <div class="rTableRow"> <div class="rTableCell"><a title="opere dei grandi a-e" href="http://massimodifa.com/dev-area/stefano-busonero/perl-project/wp-11-15/dal%20Gotico/Beato%20Angelico%20opere/opere-dei-grandi-a-e"><span style="font-family: Arial; font-size: small;">Opere Pittori A-E</span></a></div> <div class="rTableCell"><a title="opere dei grandi f-m" href="http://massimodifa.com/dev-area/stefano-busonero/perl-project/wp-11-15/dal%20Gotico/Beato%20Angelico%20opere/opere-dei-grandi-f-m"><span style="font-family: Arial; font-size: small;">Opere Pittori F-M</span></a></div> <div class="rTableCell"><a title="opere dei grandi n-r" href="http://massimodifa.com/dev-area/stefano-busonero/perl-project/wp-11-15/dal%20Gotico/Beato%20Angelico%20opere/opere-dei-grandi-n-r"><span style="font-family: Arial; font-size: small;">Opere Pittori N-R</span></a></div> <div class="rTableCell"><a title="opere dei grandi s-z" href="http://massimodifa.com/dev-area/stefano-busonero/perl-project/wp-11-15/dal%20Gotico/Beato%20Angelico%20opere/opere-dei-grandi-s-z"><span style="font-family: Arial; font-size: small;">Opere Pittori S-Z</span></a></div> </div> </div> </div> </div> </div> <!-- Inizio Codice Shinystat --><!-- Fine Codice Shinystat --></div>'; $subst = "%20"; $result = preg_replace($re, $subst, $str); echo "The result of the substitution is ".$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 PHP, please visit: http://php.net/manual/en/ref.pcre.php