Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • 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

~
~
gs

Test String

Substitution

Processing...

Code Generator

Generated Code

$re = '~\[quote name=&#39;(.+?)&#39;(.*?)\](.*?)\[/quote\]~s'; $str = '[quote name=&#39;Hale&#39; timestamp=&#39;1366473099&#39; post=&#39;272041&#39;]<br /> Sì, ma come mai non chiudono siti come TNT ecc se è illegale, e poi, io c&#39;avessi i soldi mi comprerei anche i dvd, ma ...<br /> [/quote]<br /> Mi sono chiesto spesso anch&#39;io perché non chiudano siti che violano palesemente il diritto d&#39;autore, ma non ho mai trovato la risposta. Certo che, potevi chiederglielo tu visto che hai avuto la fortuna di incontrarli. <img src=\'http://localhost/forum/public/style_emoticons/<#EMO_DIR#>/003.gif\' class=\'bbc_emoticon\' alt=\';-)\' /> Probabilmente hanno le loro priorità. Penso che prima della pirateria, si concentrino sulla lotta contro la pedopornografia.<br /> Poi l&#39;obiezione che spesso viene fatta a chi scarica illegalmente e si giustifica dicendo di non avere molti soldi è: &quot;non si tratta di beni di prima necessità: puoi farne benissimo a meno. In tempi di crisi si deve tirare la cinghia.&quot;<br /> Poi c&#39;è sempre chi si giustifica con l&#39;argomentazione seguente: &quot;Chi scarica illegalmente, non sarebbe comunque disposto a pagare per quei prodotti. Per cui il danno in realtà non esiste. &quot;'; $subst = "[quote=\"$1\"]$3[/quote]"; $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