Regular Expressions 101

Save & Share

  • Regex Version: ver. 2
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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 = '/(<a\b[^<]*?|(?<!^)\G)([^\/]*?)%20(?=(?![^\/]*\.jpg">)[^\/"]*">)/'; $str = '<a href="http://example.com/path/to-some-folder/another%20folder/one%20more520folder/34%20-%20kv34%20-%20tomba%20di%20thumtmose%20iii"> KV34 Tomba di Thutmose III</a>:</b> Nella foto, la pianta della tomba</font></p> </td> </tr> </tbody></table> </div> <div align="center"> <div align="center"> <table border="1" width="96%" id="table4"> <tbody align="left"><tr> <td width="11%" align="center"> <a href="http://example.com/path/to-some-folder/another%20folder/one%20more520folder/uploads/2012/02/some%20folder/another%20folder/06%20antichi%20egizi%20-%20Tomba%20di%20Amenofi.jpg"> <img border="0" src="http://example.com/path/to-some-folder/another%20folder/one%20more520folder/uploads/2012/02/some%20folder/another%20folder/06%20antichi%20egizi%20-%20Tomba%20di%20Amenofi%20ante.jpg" width="80" height="64" alt="/06 antichi egizi - Tomba di Amenofi" /></a></td> <td width="87%" class="style4"> <p class="style3"> <b><a href="http://example.com/path/to-some-folder/another%20folder/one%20more520folder/35%20KV35%20Tomba%20di%20Amenofi%20II">KV35 Tomba di Amenofi II</a>; </b> Nella foto, il re davanti alla dea Hathor che gli offra il segno della vita.</p> </td> </tr> <tr> <td width="11%" align="center"> <a href="http://example.com/path/to-some-folder/another%20folder/one%20more520folder/uploads/2012/02/some%20folder/another%20folder/24%20antichi%20egizi%20-%20tomba%20di%20Horemhab.jpg"> <img border="0" src="http://example.com/path/to-some-folder/another%20folder/one%20more520folder/uploads/2012/02/some%20folder/another%20folder/24%20antichi%20egizi%20-%20tomba%20di%20Horemhab%20ante.jpg" width="80" height="59" alt="24 antichi egizi - tomba di Horemhab" /></a></td> <td width="87%" class="style4"> <div class="style3"> <b><a href="http://example.com/path/to-some-folder/another%20folder/one%20more520folder/uploads/2012/02/some%20folder/another%20folder/57%20kv57%20tomba%20di%20horemhab"> KV 57Tomba di Horemhab</a><font face="Arial" size="2">: </font></b><font face="Arial" size="2">Nella foto, il faraone è raffigurato di fronte a varie divinità</font></div> </td> </tr> <tr> <td width="11%" align="center"> <a href="http://example.com/path/to-some-folder/another%20folder/one%20more520folder/uploads/2012/02/some%20folder/another%20folder/09%20antichi%20egizi%20-%20Tomba%20di%20Tutankhamen.jpg"> <img border="0" src="http://example.com/path/to-some-folder/another%20folder/one%20more520folder/uploads/2012/02/some%20folder/another%20folder/09%20antichi%20egizi%20-%20Tomba%20di%20Tutankhamen%20ante.jpg" width="80" height="92" alt="09 antichi egizi - Tomba di Tutankhamen" /></a></td> <td width="87%" class="style4"> <b><a href="http://example.com/path/to-some-folder/another%20folder/one%20more520folder/uploads/2012/02/some%20folder/another%20folder/62%20kv62%20tomba%20di%20tutankhamen">KV62 Tomba di Tutankhamen:</a></b> Nella foto, <font face="Arial" size="2">un particolare della decorazione, con la barca solare ed i babbuini che alludono alla prima ora del libro dell\'Amduat.</font></td> </tr> <tr> <td'; $subst = "\1\2-"; $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